Using Mysql 5.0 Functions with PHP

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

jeva39
Forum Commoner
Posts: 45
Joined: Sun Aug 27, 2006 11:45 pm
Location: Panamá

Using Mysql 5.0 Functions with PHP

Post by jeva39 »

I understand that In order to have MySql 5.0 functions available in PHP, I must compile PHP with support for the mysqli extension. Please, how I can do this?

Thanks!
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

There are no MySQL5 Functions, per se. MySQLi is a different, object oriented, set of functions for interacting with MySQL. These functions have been available to PHP since PHP 4 I believe. But there is nothing keeping you from hitting MySQL5 with the standard mysql_* functions.

Keep in mind too that PHP5 comes with neither the mysql nor mysqli extension enabled by default. You have to turn either or both of them on yourself.
jeva39
Forum Commoner
Posts: 45
Joined: Sun Aug 27, 2006 11:45 pm
Location: Panamá

Post by jeva39 »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Thanks. I'm absolute new to PHP/mySql. I have installed PHP 4.3 and mySql 5.0 because my server (1planhos) don't accept for now PHP 5.0. 

My problem is that any MSQL function work. To try an example I need to use the ODBC functions. Please you can tell me what I can do?

This is the code that don't work. Don't send any error but don't process nothing:

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Pruebas</title>
<link rel="stylesheet" type="text/css" href="lib.css">
</head>
<body bgcolor="#FFFFFF" text="#996600" link="#996600" vlink="#996600" alink="#996600">
<table width="90%" border="1" align=center bgcolor="#FFFFFF"> 
<tr>
<td>
<?php 

$con = mysql_connect("localhost", "****", "****");
mysql_select_db("****");
$sql = "select id,tema,ritmo, archivo,fecha from temas order by tema";

$queryexe = mysql_query($sql);
  print($queryexe);
while(mysql_fetch_row($queryexe)) 
    { 
  $id = mysql_result($queryexe, 1); //Puede ser $id= odbc_result($queryexe, "id");
  $tema = mysql_result($queryexe, 2);  
  $ritmo = mysql_result($queryexe, 3);
  $archivo = mysql_result($queryexe, 4);
  $fecha = mysql_result($queryexe, 5);
?>
   <tr>
   <td class="listas" bgcolor="#f7efde"> <?php print ("$tema"); ?></td>
   <td class="listas" bgcolor="#f7efde"> <?php print ("$ritmo"); ?></td>
   <td class="listas" bgcolor="#f7efde"> <?php print ("$archivo"); ?></td>
   <td class="listas" bgcolor="#f7efde"> <?php print ("$fecha"); ?></td>
   </tr>
<?php }?>
</td>
</tr>
</table>					
</body>
</html>
Thanks in advanced.

Note: PHPmyAdmin neither work with this config:

Code: Select all

<?php
$i=0;
$i++;
$cfg['PmaAbsoluteUri'] = 'http://localhost/phpMyAdmin';
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['auth_type'] = 'http';
$cfg['Servers'][$i]['user']          = 'root';
$cfg['Servers'][$i]['password']      = 'mypassword';
?>
Everah | Please do not post the login credentials for your database connection/selection.

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Run the following in a new file and tell us the results please.

Code: Select all

<?php

$neg = array(0, false, '', null, 'off');
$ve = phpversion();
$os = PHP_OS;
$er = intval(error_reporting());
$rg = (in_array(strtolower(ini_get('register_globals')), $neg) ? 'Off' : 'On');
$de = (in_array(strtolower(ini_get('display_errors')), $neg) ? 'Off' : 'On');
$so = (in_array(strtolower(ini_get('short_open_tag')), $neg) ? 'Off' : 'On');
$le = '';
$cli = (php_sapi_name() == 'cli');
$eol = ($cli ? "\n" : "<br />\n");

$gle = get_loaded_extensions();
$rows = array();
$wide = 4;
$j = count($gle);
$pad = $wide - $j % $wide;
$len = max(array_map('strlen', $gle));
$func = create_function('$a', 'return str_pad($a, ' . intval($len) . ');');
$gle = array_map($func, $gle);
for($i = 0; $i < $j; $i += $wide)
{
    $le .= '   ' . implode('   ', array_slice($gle, $i, $wide)) . "\n";
}
if ($cli)
{
     $le = $eol . $le;
}
else
{
 $le = '<pre>' . $le . '</pre>';
}

$ec = array(
   'E_STRICT' => 2048, 'E_ALL' => 2047, 'E_USER_NOTICE' => 1024,
   'E_USER_WARNING' => 512, 'E_USER_ERROR' => 256, 'E_COMPILE_WARNING' => 128,
   'E_COMPILE_ERROR' => 64, 'E_CORE_WARNING' => 32, 'E_CORE_ERROR' => 16,
   'E_NOTICE' => 8, 'E_PARSE' => 4, 'E_WARNING' => 2, 'E_ERROR' => 1,
);

$e = array();
$t = $er;
foreach ($ec as $n => $v)
{
   if (($t & $v) == $v)
   {
      $e[] = $n;
      $t ^= $v;
   }
}
$er = $er . ' (' . implode(' | ', $e) . ')';

if (!$cli)
{
  echo '<html><head><title>quick info</title></head><body>' . "\n";
}

echo 'PHP Version: ' . $ve . $eol;
echo 'PHP OS: ' . $os . $eol;
echo 'Error Reporting: ' . $er . $eol;
echo 'Register Globals: ' . $rg . $eol;
echo 'Short Tags: ' . $so . $eol;
echo 'Display Errors: ' . $de . $eol;
echo 'Loaded Extensions:' . $le . $eol;

if (!$cli)
{
  echo '</body></html>' . "\n";
}

?>
jeva39
Forum Commoner
Posts: 45
Joined: Sun Aug 27, 2006 11:45 pm
Location: Panamá

Post by jeva39 »

Unfortunately, don't work. The error:

' . $le . '

'; } $ec = array( 'E_STRICT' => 2048, 'E_ALL' => 2047, 'E_USER_NOTICE' => 1024, 'E_USER_WARNING' => 512, 'E_USER_ERROR' => 256, 'E_COMPILE_WARNING' => 128, 'E_COMPILE_ERROR' => 64, 'E_CORE_WARNING' => 32, 'E_CORE_ERROR' => 16, 'E_NOTICE' => 8, 'E_PARSE' => 4, 'E_WARNING' => 2, 'E_ERROR' => 1, ); $e = array(); $t = $er; foreach ($ec as $n => $v) { if (($t & $v) == $v) { $e[] = $n; $t ^= $v; } } $er = $er . ' (' . implode(' | ', $e) . ')'; if (!$cli) { echo '' . "\n"; } echo 'PHP Version: ' . $ve . $eol; echo 'PHP OS: ' . $os . $eol; echo 'Error Reporting: ' . $er . $eol; echo 'Register Globals: ' . $rg . $eol; echo 'Short Tags: ' . $so . $eol; echo 'Display Errors: ' . $de . $eol; echo 'Loaded Extensions:' . $le . $eol; if (!$cli) { echo '' . "\n"; } ?>


The problem is from here:

Code: Select all

$le = '<pre>' . $le . '</pre>'; 
} 

$ec = array( 
   'E_STRICT' => 2048, 'E_ALL' => 2047, 'E_USER_NOTICE' => 1024, 
   'E_USER_WARNING' => 512, 'E_USER_ERROR' => 256, 'E_COMPILE_WARNING' => 128, 
   'E_COMPILE_ERROR' => 64, 'E_CORE_WARNING' => 32, 'E_CORE_ERROR' => 16, 
   'E_NOTICE' => 8, 'E_PARSE' => 4, 'E_WARNING' => 2, 'E_ERROR' => 1, 
); 

$e = array(); 
$t = $er; 
foreach ($ec as $n => $v) 
{ 
   if (($t & $v) == $v) 
   { 
      $e[] = $n; 
      $t ^= $v; 
   } 
} 
$er = $er . ' (' . implode(' | ', $e) . ')'; 

if (!$cli) 
{ 
  echo '<html><head><title>quick info</title></head><body>' . "\n"; 
} 

echo 'PHP Version: ' . $ve . $eol; 
echo 'PHP OS: ' . $os . $eol; 
echo 'Error Reporting: ' . $er . $eol; 
echo 'Register Globals: ' . $rg . $eol; 
echo 'Short Tags: ' . $so . $eol; 
echo 'Display Errors: ' . $de . $eol; 
echo 'Loaded Extensions:' . $le . $eol; 

if (!$cli) 
{ 
  echo '</body></html>' . "\n"; 
} 

?>
SORRY!!!!! NO ERRORS IN THIS CODE!!!!!

Thanks...
Last edited by jeva39 on Sat Sep 09, 2006 9:13 pm, edited 1 time in total.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

What error did PHP throw? There are no sysntax errors with the code so there should be no problems with it. It runs fine on my PHP installs.
jeva39
Forum Commoner
Posts: 45
Joined: Sun Aug 27, 2006 11:45 pm
Location: Panamá

Post by jeva39 »

I'm sorry. Was a problem created by my editor (NuSphere PhpED). I run in another editor and report this:

PHP Version: 4.4.3
PHP OS: WINNT
Error Reporting: 2047 (E_ALL)
Register Globals: Off
Short Tags: On
Display Errors: Off
Loaded Extensions:
standard bcmath calendar ctype
com ftp mysql odbc
overload pcre session tokenizer
xml wddx zlib


Thanks...
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

You are not using any error reporting in your code. The problem, I would venture to say, is some form of syntax error in your code. If you are getting a blank page it is because display_errors is off and you have an ERROR level message being thrown by PHP. Make sure you are matching all braces, paranthesis and brackets, and that you are ending all of your lines with semicolons.
jeva39
Forum Commoner
Posts: 45
Joined: Sun Aug 27, 2006 11:45 pm
Location: Panamá

Post by jeva39 »

Really I appreciate very much your help and your time. Sincerely I don't encounter a logical explanation to this problem and I think that there is some problem of configuration in my machine or bad installation of mySql/PHP programs.

I have reviewed the code often and there is no error. In addition, NuSphere (the editor I use) does not allow any syntax error so that, if it exists, it indicates in red like Visual Studio 2005 Editor and don't permit run the code. For example when it was generated the error in your code I discovered that involuntarily I erase one quotation mark.

Again, thanks and I will continue looking for the error. Regards.
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

Everah wrote:You are not using any error reporting in your code.
he means try adding mysql error reporting function mysql_error to end of every mysql_* function to get to know which one is the culprit.
like f.e.

Code: Select all

$con = mysql_connect("localhost", "****", "****") or die('MySQL Connect Error: '.mysql_error());
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Another thing to do is, at the beginning of the script, add the following lines:

Code: Select all

<?php
ini_set('error_reporting', E_ALL);
ini_set('display_errors', 1);
?>
If the page is still blank after adding these lines then you have a fatal error in your code (syntax) somewhere that needs to be dealt with.
jeva39
Forum Commoner
Posts: 45
Joined: Sun Aug 27, 2006 11:45 pm
Location: Panamá

Post by jeva39 »

This is the result:

Warning: mysql_connect() [function.mysql-connect]: Client does not support authentication protocol requested by server; consider upgrading MySQL client in C:\Inetpub\wwwroot\PHP\Function_DB_mySQL.php on line 14
MySQL Connect Error: Client does not support authentication protocol requested by server; consider upgrading MySQL client


Thanks...
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

You' certainlynot the first with that problem (not even on this forum)... So a little search from your part will help you find a solution :)
jeva39
Forum Commoner
Posts: 45
Joined: Sun Aug 27, 2006 11:45 pm
Location: Panamá

Post by jeva39 »

I found this solution:

SET PASSWORD FOR ’some_user’@’some_host’ = OLD_PASSWORD(’mypass’);

This is correct for solve the problem without affect the normal access to mySql?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

I'd rather update the libmysql.dll
There's a usable version in your mysql/bin directory.
Post Reply