1

As I understand it, the normal mysql mysql.* method library has been superseded somewhat by the library mysqli.*. Essentially, my understanding is that the new library uses all the old methods just with the letter "i" tagged onto the end of the method name. Three questions:

  1. Why have MySQL updated this library and what new features does it contain?
  2. For users of Notepad++, the language of choice can be selected from a drop-down menu, which then highlights the code much like an IDE does, for instance methods are coloured blue and are in bold font. When I first wrote some MySQL code, I used the old library methods, not being aware of the advancement. When I converted it to the new library methods, the blue/bold highlighting disappeared and returned to normal font. When I deleted the "i" in the method name, it became highlighted again. Why does Notepad++ not recognize the new methods?
  3. Are the new methods a requirement (i.e. Will the old methods still work in PHP)?
Dharman
  • 30,962
  • 25
  • 85
  • 135
imulsion
  • 8,820
  • 20
  • 54
  • 84
  • 1
    MySQLi is not different from MySQL. Here's the usual message we usually give to people using `mysql_*`: [**Please, don't use `mysql_*` functions in new code**](http://bit.ly/phpmsql). They are no longer maintained [and are officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). See the [**red box**](http://j.mp/Te9zIL)? Learn about [*prepared statements*](http://j.mp/T9hLWi) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) - [this article](http://j.mp/QEx8IB) will help you decide which. If you choose PDO, [here is a good tutorial](http://j.mp/PoWehJ). – h2ooooooo Mar 19 '13 at 18:49
  • Duplicate of http://stackoverflow.com/a/14112684/285587 – Your Common Sense Mar 19 '13 at 20:18

5 Answers5

13

Using Notepad++, highlight mysqli, then

  1. open note pad select settings
  2. select style configurator
  3. in language select php
  4. in style select WORD
  5. in user-defined key words enter the keyword you want highlighted.
    make sure there is a space after false (first item.)
    Below is a list (It's the ones I use.)
  6. Save and close.

True false
mysqli_affected_rows
mysqli_autocommit
mysqli_change_user
mysqli_character_set_name
mysqli_close
mysqli_commit
mysqli_connect_errno
mysqli_connect_error
mysqli_connect
mysqli_data_seek
mysqli_debug
mysqli_dump_debug_info
mysqli_errno
mysqli_error_list
mysqli_error
mysqli_fetch_all
mysqli_fetch_array
mysqli_fetch_assoc
mysqli_fetch_field_direct
mysqli_fetch_field
mysqli_fetch_fields
mysqli_fetch_lengths
mysqli_fetch_object
mysqli_fetch_row
mysqli_field_count
mysqli_field_seek
mysqli_field_tell
mysqli_free_result
mysqli_get_charset
mysqli_get_client_info
mysqli_get_client_stats
mysqli_get_client_version
mysqli_get_connection_stats
mysqli_get_host_info
mysqli_get_proto_info
mysqli_get_server_info
mysqli_get_server_version
mysqli_info
mysqli_init
mysqli_insert_id
mysql_kill
mysqli_more_results
mysqli_multi_query
mysqli_next_result
mysqli_num_fields
mysqli_num_rows
mysqli_options
mysqli_ping
mysqli_prepare
mysqli_query
mysqli_real_connect
mysqli_real_escape_string
mysqli_real_query
mysqli_reap_async_query
mysqli_refresh
mysqli_rollback
mysqli_select_db
mysqli_set_charset
mysqli_set_local_infile_default
mysqli_set_local_infile_handler
mysqli_sqlstate
mysqli_ssl_set
mysqli_stat
mysqli_stmt_init
mysqli_store_result
mysqli_thread_id
mysqli_thread_safe
mysqli_use_result
mysqli_warning_count

Lance Roberts
  • 22,383
  • 32
  • 112
  • 130
Richard
  • 131
  • 1
  • 3
1

I can't answer number 1 for you because I don't know the details.

2: I don't know why it's not included by default, but you can add it manually.
Go to settings->style configurator and choose php under language. Choose WORD under style.
In the box called "User-defined keywords" Add all the mysqli_* functions you use. They'll be highlighted from now on.

3: For now, they will work. It was deprecated in 5.5, which means it will throw a warning when you use it. Eventually, it will be completely removed. Still, switch over to mysqli so nothing breaks when you upgrade.

Trenton Trama
  • 4,890
  • 1
  • 22
  • 27
0

From PHP.net's FAQ about databases

Why is the MySQL extension (ext/mysql) that I've been using for over 10 years discouraged from use? Is it deprecated? What do I use instead? How can I migrate?

There are three MySQL extensions, as described under the Choosing a MySQL API section. The old API should not be used, and one day it will be deprecated and eventually removed from PHP. It is a popular extension so this will be a slow process, but you are strongly encouraged to write all new code with either mysqli or PDO_MySQL.

Migration scripts are not available at this time, although the mysqli API contains both a procedural and OOP API, with the procedural version being similar to ext/mysql.

It is not possible to mix the extensions. So, for example, passing a mysqli connection to PDO_MySQL or ext/mysql will not work.


As to your question regarding Notepad++ features, you'll have to ask it on their official forums/community.


Your 3rd question's reply is hidden in the excerpt above:

The old API should not be used, and one day it will be deprecated and eventually removed from PHP. It is a popular extension so this will be a slow process, but you are strongly encouraged to write all new code with either mysqli or PDO_MySQL.

hjpotter92
  • 78,589
  • 36
  • 144
  • 183
0

Essentially, my understanding is that the new library uses all the old methods just with the letter "i" tagged onto the end of the method name.

Not necessarily. mysqli functions are now in two forms, either procedural (like old mysql ones) or object-oriented style. (e.g. $result->fetch_array()).

From php.net

The mysqli extension features a dual interface. It supports the procedural and object-oriented programming paradigm.

Some of the new mysqli functions also accept different arguments from the old ones. Most generally, most of the functions now require a mysqli link (the mysqli connection) as their argument.

As for why they've changed it, it obviously must have a few reasons. The top ones being security and stability, and introducing the new OO-styles must be one reason.

Have a look at this for the benefits: MySQLi extension benefits

Community
  • 1
  • 1
mavili
  • 3,385
  • 4
  • 30
  • 46
0

1) According to php.net's overview

  • Object-oriented interface
  • Support for Prepared Statements
  • Support for Multiple Statements
  • Support for Transactions
  • Enhanced debugging capabilities
  • Embedded server support

2) I've never used Notepad++, I use Sublime Text 2. Text editors may not cater to every language, so maybe there's a Notepad++ plugin for mysqli?

3) The MySql overview says:

This extension is deprecated as of PHP 5.5.0, and is not recommended for writing new code as it will be removed in the future.

It might be a good idea to make the switch, it certainly wouldn't hurt and it would definitely be nice to stay up to date with the way PHP interacts with MySql.


Edit: For me writing MySqli is smoother than MySql because I don't have to include a connection at the end of a query when using the MySqli class.

$query = $mysqli->query("SELECT * FROM table");

Instead of

$query = mysql_query("SELECT * FROM table",$link);
WackyWalrus
  • 324
  • 1
  • 7