Flourish PHP Unframework
This is an archived copy of the forum for reference purposes

mysql_real_escape_string()

posted by shakeel 8 years ago

mysql_real_escape_string() this function is giving the warning

mysql_real_escape_string(): A link to the server could not be established

and how to use getAutoIncrementedValue() , Fatal error: Call to undefined method getAutoIncrementedValue()

Please provide the code you are trying to execute, and I can give you some help.

posted by wbond 8 years ago

$sql = "SELECT count(ebook_id) FROM download_master WHERE ebook_category_name = "'.mysql_real_escape_string($_GET["name"]).'";

$r = $db->query($sql); // here $db is database connection object , its working fine with every query

$db->getAutoIncrementedValue();//this giving fatal error

and mysql_real_escape_string() is giving warning like

{doc_root}
index.php(105): include('C:
wamp
www
dow...') {doc_root}
paging.php(8): mysql_real_escape_string('a') internal function mysql_real_escape_string(): A link to the server could not be established

posted by shakeel 8 years ago

shakeel,

Flourish automatically determines the best database extension to use, so if your $db is an fDatabase object, you should not be directly calling other methods which belong to lower level mysql classes, or related functions. Using fDatabase's query() method allows you to create placeholders in the SQL and then insert the values as separate parameters and it will automatically determine the best method of escaping them. Example:

$db->query("SELECT count(ebook_id) FROM download_master WHERE ebook_category_name = %s", $_GET['name']);

The %s above indicates that the value is of type string and should be escaped as a string. It is somewhat similar to sprintf() concept. For more information regarding the placeholders see: http://flourishlib.com/api/fDatabase#escape

You could alternatively use escape directly, although the above method is much cleaner in my opinion rather than cat-ing strings together. The returned object from a database query is an fResult object, with methods documented here: http://flourishlib.com/api/fResult

So if you are looking to get the count value, you should be able to do something like:

$result = $db->query("SELECT count(ebook_id) FROM download_master WHERE ebook_category_name = %s", $_GET['name']);
$count  = $result->fetchScalar();
posted by mattsah 8 years ago