php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42902 can't call mysqli->set_charset() after mysql_init()
Submitted: 2007-10-09 14:40 UTC Modified: 2007-10-09 21:58 UTC
From: carsten_sttgt at gmx dot de Assigned:
Status: Closed Package: MySQLi related
PHP Version: 5.2.4 OS: Windows_NT
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: carsten_sttgt at gmx dot de
New email:
PHP Version: OS:

 

 [2007-10-09 14:40 UTC] carsten_sttgt at gmx dot de
Description:
------------
Hello,

mysqli->set_charset() only works after mysqli->real_connect(), but not after mysql_init().

BTW:
I don't understand, why there is no MYSQLI_SET_CHARSET_NAME for mysqli->options()? Because that's the correct way, described in the MySQL C API.

Regards,
Carsten


Reproduce code:
---------------
----- don't works -----
<?php
$mysqli = mysqli_init();

$mysqli->set_charset('utf8');
echo 'Charset is: ', $mysqli->character_set_name();

$mysqli->real_connect('localhost','root','','test');
?>


----- works -----
<?php
$mysqli = mysqli_init();

$mysqli->real_connect('localhost','root','','test');

$mysqli->set_charset('utf8');
echo 'Charset is: ', $mysqli->character_set_name();
?>


Expected result:
----------------
Charset is: utf8

Actual result:
--------------
Warning: mysqli::set_charset() [function.mysqli-set-charset]: invalid object or resource mysqli in \test.php on line 4
Charset is:
Warning: mysqli::character_set_name() [function.mysqli-character-set-name]: invalid object or resource mysqli in \test.php on line 5

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-10-09 16:57 UTC] scottmac@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

MYSQLI_SET_CHARSET_NAME was added for PHP 5.3, I've now backported this to the 5.2 branch.
 [2007-10-09 21:58 UTC] carsten_sttgt at gmx dot de
Hello Scott,

thanks, I've made a test with "php5.2-win32-200710092030.zip" and:
| $mysqli = mysqli_init();
| mysqli_options($mysqli, MYSQLI_SET_CHARSET_NAME, 'utf8');
| mysqli_real_connect($mysqli, 'localhost', 'root', '', 'test');
| echo 'Charset is: ', mysqli_character_set_name($mysqli);
is working now like expected :-)

Just to clarify:
| $mysqli = mysqli_init();
| mysqli_set_charset($mysqli, 'utf8');
still does not work.

But I guess that's a documentation problem? In the manual [1] (not only for mysqli_set_charset) I can read:
| link  Procedural style only: A link identifier
|       returned by mysqli_connect() or mysqli_init()

and this should be:
| link  Procedural style only: A link identifier
|       returned by mysqli_connect() or mysqli_real_connect()

Regards,
Carsten

[1] http://www.php.net/manual/en/function.mysqli-set-charset.php
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Nov 22 11:01:29 2024 UTC