note 94853 added to function.mysql-query
| From: | jbud at jbud dot co dot cc | Date: | Sat, 28 Nov 2009 22:52:36 +0000 |
| Subject: | note 94853 added to function.mysql-query | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-163365@lists.php.net to get a copy of this message | ||
This is a simple function to use for doing mysql querys
config.php:
<?php
$config_url = "localhost";
$config_user = "Goober";
$config_password = "I4m4k1ttyc4t";
?>
functions.php:
<?php
function doSql($query, $type) {
require('config.php');
$doSql_Connect = mysql_connect($config_url, $config_user, $config_password);
mysql_select_db($config_db, $doSql_Connect);
if ($type == "RETURNARRAY") {
return mysql_fetch_array(mysql_query($query, $doSql_Connect));
} elseif ($type == "RETURN") {
return mysql_query($query, $doSql_Connect);
}
}
?>
usage:
<?php
$mysqlarray = doSql("SELECT * FROM stuff LIMIT 10","RETURNARRAY");
print_r($mysqlarray);
if (!doSql("INSERT INTO stuff ('name', 'age') VALUES ('bill',
'86')","RETURN")){
die("Failed to insert<br>".mysql_error());
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 71.237.144.226
----
Manual Page -- http://www.php.net/manual/en/function.mysql-query.php
Edit -- https://master.php.net/note/edit/94853
Del: integrated -- https://master.php.net/note/delete/94853/integrated
Del: useless -- https://master.php.net/note/delete/94853/useless
Del: bad code -- https://master.php.net/note/delete/94853/bad+code
Del: spam -- https://master.php.net/note/delete/94853/spam
Del: non-english -- https://master.php.net/note/delete/94853/non-english
Del: in docs -- https://master.php.net/note/delete/94853/in+docs
Del: other reasons-- https://master.php.net/note/delete/94853
Reject -- https://master.php.net/note/reject/94853
Search -- https://master.php.net/manage/user-notes.php