Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8703941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:58:42+00:00 2026-06-13T02:58:42+00:00

I have a bunch of code that needs transitioned from PHP’s mysql_* to mysqli_*

  • 0

I have a bunch of code that needs transitioned from PHP’s mysql_* to mysqli_*

In Sublime Text 2 I can easily do a find for mysql_ and replace it with mysqli_

The problem I run into is:

mysql_query($query, $link_identifier)

versus

mysqli_query($link, $query)

To make things worse $query is not always the variable name for the query string.
I may have:

$q_test = "SELECT `lName` FROM `users` ORDER BY `lName`";
$rstest = mysql_query($q_test, $DB) or die(mysql_error($DB));

and

$q_tester = "SELECT `address` FROM `users_address` ORDER BY `id`";
$rstester = mysql_query($q_tester, $DB) or die(mysql_error($DB));

on the same page.

Is there a way for me to construct a macro in Sublime Text 2 to change both of the above to:

$rstest = mysqli_query($DBi, $q_test) or die(mysqli_error($DBi));
$rstester = mysqli_query($DBi, $q_tester) or die(mysqli_error($DBi));

at the same time? I’m thinking I can use a regex to accomplish this I just have no idea how and where to start.

UPDATE

So, after a little hunting I found that I can search for:

mysql_query\(\$(\w+), \$DB\)

and replace with

mysqli_query\(\$DBi\, \$$1)

which converts
$rstest = mysql_query($q_test, $DB) or die(mysql_error($DB));

to

$rstest = mysqli_query($DBi, $q_test) or die(mysql_error($DB)); for me but…

turns out you can’t macro Find and Replace. Do I have any options?

UPDATE

So it looks like I can use the plugin Reg Replace to accomplish what I want even though I have more setup to do.

Using Reg Replace I can chain multiple find and replace actions together and bind them to a keystroke so I can basically do a series of find and replace actions to get what I need:

  1. Find and Replace mysql_ with mysqli_
  2. Find and Replace $DB with $DBi
  3. Find and Replace , $DBi) or die( with ) or die(
  4. Find and Replace mysqli_query($ with mysqli_query($DBi, $

Those basically get

$rstest = mysql_query($q_test, $DB) or die(mysql_error($DB));

converted to

$rstest = mysqli_query($DBi, $q_test) or die(mysqli_error($DBi));

for me in a single keystroke. It’s not optimal but it does the trick. I’m still looking for a simple, no plugin solution however.

UPDATE
The above works with Sublime Text 3 using the updated Reg Replace plugin

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T02:58:43+00:00Added an answer on June 13, 2026 at 2:58 am

    Since sublime does not have the ability to record find and replace using a regex in a macro for now I’m going to use Reg Replace and a series of chained find and replace commands to get what I’m looking for.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a bunch of PHP code that is auto-generated and it puts all
I have a regex that needs to match a bunch of characters. The code
I have a bunch of generic code that is used a lot, which i'd
I have a bunch of code in a routine that looks a bit like
I have a bunch of Workflow foundation 4.0 RC code activities that consume web
I have code that loads a bunch of images into hidden img elements and
I have some code that creates a bunch of UITextViews and puts them into
I have a .net assembly that contains data access code (a bunch of Typed
I have a git repo with a bunch of source code, and when that
Project is C#. So I have a bunch of multithreaded code that is designed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.