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! 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 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: 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? 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? 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 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 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 :'( 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 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.'); } ?> 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 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! 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! Link to comment https://forums.phpfreaks.com/topic/72934-solved-mysql_connect-help/#findComment-367975 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.