Jimmy058910 Posted July 8, 2007 Share Posted July 8, 2007 I have just recently setup AMP and checked many many sources for the correct way to do so etc. After trying a php code that came with the book PHP & MySQL for Dummies Third Edition, I keep recieving an error and have tried many things but still no result, hence why I am here Here is the code for the test I am running <?php /* Program: mysql_up.php * Desc: Connects to MySQL Server and * outputs settings. */ echo "<html> <head><title>Test MySQL</title></head> <body>"; $host="localhost"; $user=""; $password=""; $cxn = mysqli_connect($host,$user,$password); $sql="SHOW STATUS"; $result = mysqli_query($cxn,$sql); if($result == false) { echo "<h4>Error: ".mysqli_error($cxn)."</h4>"; } else { /* Table that displays the results */ echo "<table border='1'> <tr><th>Variable_name</th> <th>Value</th></tr>"; for($i = 0; $i < mysqli_num_rows($result); $i++) { echo "<tr>"; $row_array = mysqli_fetch_row($result); for($j = 0;$j < mysqli_num_fields($result);$j++) { echo "<td>".$row_array[$j]."</td>\n"; } } echo "</table>"; } ?> </body></html> The error I recieve is as follows; Fatal error: Call to undefined function mysqli_connect() in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\mysqltest.php on line 13 In the book, it says to change lines 9-11 or something. I have tried eeeeevery single option I could possible think of. I know the password for SURE, the host is localhost so that for SURE, and the other thing should be root, and I tried mysql50, my e-mail, etc, all combinations. So, please help thanks! Quote Link to comment Share on other sites More sharing options...
vbnullchar Posted July 8, 2007 Share Posted July 8, 2007 http://www.phpfreaks.com/forums/index.php/topic,126354.0.html Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted July 8, 2007 Share Posted July 8, 2007 Your code is fine. It's just that PHP cannot call the function mysqli_connect. You need to enable the mysqli php extension in the php.ini (php_mysqli.dll) in order to use mysqli_* functions. The topic vbnullchar has linked you to will walk you through it. Quote Link to comment Share on other sites More sharing options...
Jimmy058910 Posted July 9, 2007 Author Share Posted July 9, 2007 Hmmm... no result... Maybe there is something during setup that I messed up. I also tried removing the ; before mysqli single (thought that was for php 5 and above, you should know I am using php 5), dual, by themselves etc. So frustrated setting this up it's ridiculous. Thanks for the help though, will get it eventually.. sigh I wish there was a php.ini file to be copy pasted from somewhere, because I swear this is correct but yet still doesnt work... Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted July 10, 2007 Share Posted July 10, 2007 There is no standard php.ini file as php setups can vary. Your php.ini file is probably setup correctly. The problem lies with PHP loading the mysql extension. Can you enable a setting called display_startup_errors too within the php.ini. When you restart Apache errors should be displayed if PHP is having problems when Apache starts up. Also can you verify that php is using the php.ini file you are editing? You can check this by running phpinfo(); and then looking at the Configuration File (php.ini) Path or Loaded Configuration File line. One or the other should be set to the full path of loaded php.ini file, eg if your php.ini is in C:\WINDOWS one of the lines should read C:\WINDOWS\php.ini. If none of lines end with php.ini then PHP has not managed to load the php.ini I know this can be very frustrating. We get these sort of posts all the time. Quote Link to comment Share on other sites More sharing options...
Jimmy058910 Posted July 11, 2007 Author Share Posted July 11, 2007 Ok, think you found my problem... The configuration file (php.ini) path is set at C:\WINDOWS, when I really have it under C:\PHP Also the loaded configuration file line says: (none) Just trying to figure how to fix this, if you see it and I havent made this solved, please inform me Thanks a lot for the help! Quote Link to comment Share on other sites More sharing options...
Jimmy058910 Posted July 11, 2007 Author Share Posted July 11, 2007 Couldnt even find where to edit those two lines, thats how noob I am Using Apache 2.2.4 PHP 5.2.3 MySQL 5 Community Thanks again for the huge help, pretty positive it will work after this Quote Link to comment Share on other sites More sharing options...
rameshfaj Posted July 11, 2007 Share Posted July 11, 2007 Either update the php.ini file or use simply mysql_connect(). Quote Link to comment Share on other sites More sharing options...
Jimmy058910 Posted July 11, 2007 Author Share Posted July 11, 2007 I went through the entire php.ini and didnt find anything that had the configuration path to edit (currently at C://WINDOWS) or to change the loaded configuration file (currently set as "None") I'm sorry, I dont know what you mean by using "mysql_connect()". I thought this had to be changed under the Apache httpd.conf file, but went through that as well and didnt find anything in there either. So, please be more specific as I am 100% new to this, and the prupose of setting all this up is so that I can learn and use my books I had purchased. Thanks! Quote Link to comment Share on other sites More sharing options...
per1os Posted July 11, 2007 Share Posted July 11, 2007 <?php /* Program: mysql_up.php * Desc: Connects to MySQL Server and * outputs settings. */ echo "<html> <head><title>Test MySQL</title></head> <body>"; $host="localhost"; $user=""; $password=""; $cxn = mysql_connect($host,$user,$password); $sql="SHOW STATUS"; $result = mysql_query($sql); if($result == false) { echo "<h4>Error: ".mysqli_error($cxn)."</h4>"; } else { /* Table that displays the results */ echo "<table border='1'> <tr><th>Variable_name</th> <th>Value</th></tr>"; for($i = 0; $i < mysql_num_rows($result); $i++) { echo "<tr>"; $row_array = mysql_fetch_row($result); for($j = 0;$j < mysql_num_fields($result);$j++) { echo "<td>".$row_array[$j]."</td>\n"; } } echo "</table>"; } ?> </body></html> www.php.net/mysql_connect Nearly the same usage except without using i you are not required to put the connection string in the function. php.ini file is usually searched for in C:\Windows C:\Windows\System32 C:\php In an order similiar to that. If it is not found in windows it searches system32 etc. It is just automatic. Generally you should change them all if they are located in those locations if you make a modification. Or remove the 2 you do not want to use. MySQLi I believe is compiled with PHP5 only, but if not it should be inside there as an extension of ;extension=php_mysqli.dll remove the ; from that line to allow it and you may have to restart apache. Quote Link to comment Share on other sites More sharing options...
Jimmy058910 Posted July 11, 2007 Author Share Posted July 11, 2007 Ok, so although it says C:\Windows and has None for loaded configuration file, it still is getting to C:\PHP\php.ini right? And yes, I have php 5, so I have to activate the mysqli extension I know, but should I have both activated? Does it matter? And is there anything else I should know or activate for php 5.2.3? I'm still very confused about what you saying about the mysql_connect() function. This whole mysql_up php code was right out of the book is used to check if it works or not I thought? So from what I think you said, how would removing it help? And for verification purposes, my host (localhost) is correct right? And user should be root right? But when I installed mysql I called the service name mysql50 because the book told me to. And I know the password already for mysql, just wanna make sure I have the right combination for when I test new things and not have to keep testing different combinations, thanks. Quote Link to comment Share on other sites More sharing options...
per1os Posted July 11, 2007 Share Posted July 11, 2007 Ok, so although it says C:\Windows and has None for loaded configuration file, it still is getting to C:\PHP\php.ini right? And yes, I have php 5, so I have to activate the mysqli extension I know, but should I have both activated? Does it matter? And is there anything else I should know or activate for php 5.2.3? I'm still very confused about what you saying about the mysql_connect() function. This whole mysql_up php code was right out of the book is used to check if it works or not I thought? So from what I think you said, how would removing it help? And for verification purposes, my host (localhost) is correct right? And user should be root right? But when I installed mysql I called the service name mysql50 because the book told me to. And I know the password already for mysql, just wanna make sure I have the right combination for when I test new things and not have to keep testing different combinations, thanks. Books are nice, but are not "real" world. Yes, even though it states in C:\windows as long as there is not a php.ini file located there the one in the php directory is the one to modify. Having both active in php.ini does not matter one way or the other. As long as mysqli is uncommented it should work, you may need to restart apache for the settings to take affect. mysql_connect is nearly the same as mysqli_connect, just an older version with minor differences. mysqli is more efficient as it is the newer and latest/greatest version. mysqli and mysql are the same thing basically. Quote Link to comment Share on other sites More sharing options...
Jimmy058910 Posted July 11, 2007 Author Share Posted July 11, 2007 Oh, I didnt catch that I used mysqli, was wondering what ramesh meant by that, lol. Ok, so I tried using mysql_connect and same error :-\ Yeah, I do restart apache all the time, one thing I did learn from the book lol. Now I just got no idea what to do, thought the wrong path was the problem... Quote Link to comment Share on other sites More sharing options...
per1os Posted July 11, 2007 Share Posted July 11, 2007 create a file called phpinfo.php <?php phpinfo(); ?> That will tell you where the php.ini file is coming from. Wherever that says search the directory and locate it and either A delete it or B make it the same as the one you modified in your php folder. The undefined function error call means that the mysql or mysqli extensions have not been either uncommented (removing the or added under the extension portion of the php.ini file. Quote Link to comment Share on other sites More sharing options...
Jimmy058910 Posted July 11, 2007 Author Share Posted July 11, 2007 Here is a table of the php info, just the top part of it (attached as a small word doc), tell me if anything looks wrong. [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
per1os Posted July 11, 2007 Share Posted July 11, 2007 mysql MySQL Support enabled Active Persistent Links 0 Active Links 0 Client API version 3.23.58 MYSQL_MODULE_TYPE external MYSQL_SOCKET /tmp/mysql.sock MYSQL_INCLUDE -I/usr/local/mysql/include MYSQL_LIBS -L/usr/local/mysql/lib -lmysqlclient Directive Local Value Master Value mysql.allow_persistent On On mysql.connect_timeout 60 60 mysql.default_host no value no value mysql.default_password no value no value mysql.default_port no value no value mysql.default_socket no value no value mysql.default_user no value no value mysql.max_links Unlimited Unlimited mysql.max_persistent Unlimited Unlimited mysql.trace_mode Off Off Came from my php.ini, you should have a table like that. Also my "Configure Command" looks like this: Configure Command './configure' '--with-config-file-path=/etc' '--with-mysql=/usr/local/mysql' '--enable-ftp' '--enable-bcmath' '--disable-debug' '--with-gd' '--with-jpeg-dir=../jpeg-6b' '--with-png-dir=../libpng-1.2.5' '--with-zlib-dir=../zlib-1.1.4' '--with-png' '--with-zlib' '--with-imap-ssl=../imap-2001a' '--with-apxs=/usr/local/apache/sbin/apxs' '--with-freetype' '--with-ttf' '--with-openssl=/usr/local/openssl' '--with-openssl-dir=/usr/local/openssl' '--with-curl' '--with-pear' '--enable-mbstring' '--with-calendar=shared' '--enable-memory-limit' '--enable-magic-quotes' '--enable-wddx' '--with-mhash' '--with-kerberos' Notice the --with-mysql portion, I do not think that is required because I know that the one I run locally was not compiled with that command but yea. I should also note i am running PHP 4.4.x Quote Link to comment Share on other sites More sharing options...
Jimmy058910 Posted July 11, 2007 Author Share Posted July 11, 2007 I have this [MySQL] mysql.allow_persistent = On mysql.max_persistent = -1 mysql.max_links = -1 mysql.default_port = mysql.default_socket = mysql.default_host = mysql.default_user = mysql.default_password = mysql.connect_timeout = 60 mysql.trace_mode = Off [MySQLi] mysqli.max_links = -1 mysqli.default_port = 3306 mysqli.default_socket = mysqli.default_host = mysqli.default_user = mysqli.default_pw = mysqli.reconnect = Off [mSQL] msql.allow_persistent = On msql.max_persistent = -1 msql.max_links = -1 As for my configure command, I dont see that anywhere, is that in the php.ini? Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted July 11, 2007 Share Posted July 11, 2007 OK. Hold it there chaps. PHP is not reading Jimmy058910's php.ini file. So anything you do to the php.ini wont matter. Also PHP only searches in C:/WINDOWS, C:/WINDOWS/System32 or the Windows Path and/or Registery for the php.ini. If the Configuration File (php.ini) Path line is set to just C:/WINDOWS or the Loaded Configuration File line is set to nothing. then then PHP is not reading any php.ini file and is using the default php.ini settings built in to php itself. As you have the php.ini C:/php instead I would suggest you add the PHP folder to the Windows Path. To do so go to Start > Control Panel > System > Advanced Tab > Environment Variables button. Now scroll down the list of variables in the System Variables box and select PATH. Now press the Edit button. After you have done that, immediately press the End key on your keyboard. This will send the cursor to the very end of the text field (which should stop you from deleting anything already set within the PATH variable). Now type the following exactly: ;C:\php;. Now press Ok for all open windows to close them. Now restart Windows for the changes to take affect When you log back into Windows run the phpinfo function again within a .php file and check that PHP is now reading your php.ini located in C:/php by again looking at the Configuration File (php.ini) Path or Loaded Configuration File line. One of those two lines should be now set to C:/php/php.ini. If they are php is now reading your php.ini file. Any changes you make to the php.ini should be loaded. NOTE: When you make any changes to the php.ini you must restart your server (eg: Apache, IIS etc) for the changes to take affect. Quote Link to comment Share on other sites More sharing options...
Jimmy058910 Posted July 11, 2007 Author Share Posted July 11, 2007 Tried both of these and no result %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program files\PC-Doctor for Windows XP\WINDSAPI;C:\Program Files\QuickTime\QTSystem\;;C:\php; %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program files\PC-Doctor for Windows XP\WINDSAPI;C:\Program Files\QuickTime\QTSystem\;C:\php; the 2nd one would be correct right? Quote Link to comment Share on other sites More sharing options...
per1os Posted July 11, 2007 Share Posted July 11, 2007 Did you try copying the php.ini and putting it in the C:\Windows directory and restarting the server? Quote Link to comment Share on other sites More sharing options...
Jimmy058910 Posted July 12, 2007 Author Share Posted July 12, 2007 It seemed to have worked. It crossed my mind the whole time, but really figured it had to read from the php folder the whole time... but for sure 100% this is ok to do? Just got to keep them updated at both spots or what? Quote Link to comment Share on other sites More sharing options...
per1os Posted July 12, 2007 Share Posted July 12, 2007 It seemed to have worked. It crossed my mind the whole time, but really figured it had to read from the php folder the whole time... but for sure 100% this is ok to do? Just got to keep them updated at both spots or what? Yep it is how it should be done. It is in the php install manual. Quote Link to comment Share on other sites More sharing options...
Jimmy058910 Posted July 12, 2007 Author Share Posted July 12, 2007 Alright, sounds great, you da man! Topic SOLVED Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.