hungryOrb Posted October 12, 2007 Share Posted October 12, 2007 Hello! I just installed PHP and MySQL to work with localhost. However, when I try the mysql_connect function, it returns: Fatal error: Call to undefined function mysql_connect() in ..\index.php on line 13 ..\ is usually the whole line obviously. I asked someone I knew, if this was because MySQL was not installed properly, and he thinks it is. Does anyone know how to remedy this? TIA! Quote Link to comment https://forums.phpfreaks.com/topic/72934-solved-mysql_connect-help/ Share on other sites More sharing options...
adam291086 Posted October 12, 2007 Share Posted October 12, 2007 Post the code, its not a mysql errorm, its the fact your calling an undefined php function Quote Link to comment https://forums.phpfreaks.com/topic/72934-solved-mysql_connect-help/#findComment-367813 Share on other sites More sharing options...
hungryOrb Posted October 12, 2007 Author Share Posted October 12, 2007 <html> <body> <?php function connect(){ $dbserver = '127.0.0.1'; $dbuser = 'WOOPS'; $dbpassword = 'PASSWORD'; $dbschema = 'db'; try{ $db = mysql_connect($dbserver, $dbuser, $dbpassword); }catch(Exception $e){ echo $e->getMessage(); } if ($db==false){ echo "Database connection failure\n<br>"; echo mysql_error(); } mysql_select_db($dbschema); echo mysql_error(); return $itdblink; } function disconnect(){ mysql_close(); } connect(); $query('SELECT * FROM test'); $result = mysql_query($query) or die('Query messed up: ' . mysql_error()); echo $result; ?> </body> </html> KK here tis: Quote Link to comment https://forums.phpfreaks.com/topic/72934-solved-mysql_connect-help/#findComment-367825 Share on other sites More sharing options...
adam291086 Posted October 12, 2007 Share Posted October 12, 2007 are you just wanting to connect to a database and run a query? Quote Link to comment https://forums.phpfreaks.com/topic/72934-solved-mysql_connect-help/#findComment-367830 Share on other sites More sharing options...
hungryOrb Posted October 12, 2007 Author Share Posted October 12, 2007 yes ^^ I realise I don't need a function at this point, but that shouldn't matter right? Quote Link to comment https://forums.phpfreaks.com/topic/72934-solved-mysql_connect-help/#findComment-367831 Share on other sites More sharing options...
adam291086 Posted October 12, 2007 Share Posted October 12, 2007 Try this. <?php $db_server ="edit"; $db_user = "edit"; $db_pass = "edit"; $db_name = "edit"; $con = mysql_connect("$db_server","$db_user","$db_pass"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("$db_name", $con); $result = mysql_query("SELECT * FROM your tabel"); while($row = mysql_fetch_array($result)) { echo $row['any column in your table']; echo "<br />"; } mysql_close($con); ?> I am new to php so i can't guarentee this will work Quote Link to comment https://forums.phpfreaks.com/topic/72934-solved-mysql_connect-help/#findComment-367842 Share on other sites More sharing options...
adam291086 Posted October 12, 2007 Share Posted October 12, 2007 Just edited the code a little Quote Link to comment https://forums.phpfreaks.com/topic/72934-solved-mysql_connect-help/#findComment-367843 Share on other sites More sharing options...
hungryOrb Posted October 12, 2007 Author Share Posted October 12, 2007 Thanks for trying, but same error. It seems like Apache is not recognising the mysql function mysql_connect().. no clue :'( Quote Link to comment https://forums.phpfreaks.com/topic/72934-solved-mysql_connect-help/#findComment-367848 Share on other sites More sharing options...
adam291086 Posted October 12, 2007 Share Posted October 12, 2007 paste in the error Quote Link to comment https://forums.phpfreaks.com/topic/72934-solved-mysql_connect-help/#findComment-367849 Share on other sites More sharing options...
Aureole Posted October 12, 2007 Share Posted October 12, 2007 Well to determine if the function truly does exist I believe you would use something like this: <?php if(function_exists(mysql_connect) { echo('Function exists.'); } else { echo('Function does not exist.'); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/72934-solved-mysql_connect-help/#findComment-367851 Share on other sites More sharing options...
adam291086 Posted October 12, 2007 Share Posted October 12, 2007 http://drupal.org/node/27119, some other people with the same problem. Follow the steps, will only work for php5 Quote Link to comment https://forums.phpfreaks.com/topic/72934-solved-mysql_connect-help/#findComment-367856 Share on other sites More sharing options...
hungryOrb Posted October 12, 2007 Author Share Posted October 12, 2007 Thankyou guys, I'll check this out when I get home. ;] much appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/72934-solved-mysql_connect-help/#findComment-367857 Share on other sites More sharing options...
wildteen88 Posted October 12, 2007 Share Posted October 12, 2007 Thankyou guys, I'll check this out when I get home. ;] much appreciated! If you searched this forum with that error message you would of gotten the answer adam291086 has just came up with. There is even a sticky titled as the error message you are getting within the PHP Help board! Quote Link to comment https://forums.phpfreaks.com/topic/72934-solved-mysql_connect-help/#findComment-367975 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.