ukweb Posted September 26, 2008 Share Posted September 26, 2008 Hi I have a CMS system which I am slowly replacing with a new version which is basically coded better for speed improvements. One part just wont work though. this chunk of code is in a file called 'framework.php' and is required by 'index.php'. As far as I can see its coded correctly, its code lifted straight from the old framework (which runs side by side with this one until the transition is complete. There are no code duplications as old code is removed as new code is added). Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /www/allturf.co.uk/admin/framework.php on line 194 is the error. heres the code at fault: function new_page($title, $text, $short_text, $lang) { global $date_time, $uni_gen; $text = strip_html($text); $insertSQL = sprintf("INSERT INTO pages (lang, p1, p2, title, uni_id, date_time) VALUES (%s, %s, %s, %s, %s, %s)", GetSQLValueString($lang, "text"), GetSQLValueString($short_text, "text"), GetSQLValueString($text, "text"), GetSQLValueString($title, "text"), GetSQLValueString($uni_gen, "text"), GetSQLValueString($date_time, "text")); mysql_select_db($database_sql, $sql); $result = mysql_query($insertSQL, $sql) or die(mysql_error()); if ($result) { return true; } } Link to comment https://forums.phpfreaks.com/topic/125915-invalid-link-resource-cant-see-why-and-its-really-bugging-me/ Share on other sites More sharing options...
Jibberish Posted September 26, 2008 Share Posted September 26, 2008 mysql_select_db($database_sql, $sql) this needs to contain mysql_select_db ( string $database_name [, resource $link_identifier ] ) ie, <?php $con = mysql_connect('server', 'username', 'password') mysql_select_db('dbname', $con); ?> Link to comment https://forums.phpfreaks.com/topic/125915-invalid-link-resource-cant-see-why-and-its-really-bugging-me/#findComment-651127 Share on other sites More sharing options...
ukweb Posted September 26, 2008 Author Share Posted September 26, 2008 ...That's further up in the 'framework.php' file; $hostname_sql = "localhost"; $database_sql = "db26403_allt"; $username_sql = "root"; $password_sql = "root"; $sql = mysql_pconnect($hostname_sql, $username_sql, $password_sql) or trigger_error(mysql_error(),E_USER_ERROR); This is why I cant understand it, everything is there and it does appear to be coded correctly. No other scripts are having problems just this one... Link to comment https://forums.phpfreaks.com/topic/125915-invalid-link-resource-cant-see-why-and-its-really-bugging-me/#findComment-651131 Share on other sites More sharing options...
Jibberish Posted September 26, 2008 Share Posted September 26, 2008 mysql_pconnect has to be used with caution when it comes to apachy/msql as it needs abit of fine tuneing due the fact that it can run out of connections, thus giving that error. Try just using the normal mysql_connect, unless there is a reason you need the connection to stay active after your script ends. Link to comment https://forums.phpfreaks.com/topic/125915-invalid-link-resource-cant-see-why-and-its-really-bugging-me/#findComment-651137 Share on other sites More sharing options...
ranjuvs Posted September 26, 2008 Share Posted September 26, 2008 You called the function mysql_select_db($database_sql, $sql); inside a function and hence can't access the variables declared outside. Either you have to pass the variables "$database_sql" and "$sql" to the function. (I guess you are not using classes) Link to comment https://forums.phpfreaks.com/topic/125915-invalid-link-resource-cant-see-why-and-its-really-bugging-me/#findComment-651140 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.