Results 1 to 9 of 9
Thread: PHP MySQL
Hybrid View
-
23rd January 2013 20:57 #1
PHP MySQL
process.phpHTML Code:<form method="post" action="process.php"> <input type="text" name="firstname" /><br> <input type="submit" name="submit" value="Submit" />
Error 2PHP Code:$first_name = $_POST['firstname'];
$dbc = mysql_connect('localhost','root','','ninja') or die("Error 1");
$q = "INSERT INTO ivan (first_name) VALUES('$first_name')";
mysql_query($q) or die("Error 2");
INSERT INTO ivan (first_name) VALUES('Peter Jackson'); .
php ?
-
23rd January 2013 21:47 #2
-
24th January 2013 12:37 #3
-
24th January 2013 13:04 #4
Google.
, mysql_connect . 'ninja', , , , true false .PHP Code:...
... or die('Error 2: ' . mysql_error());
$dbc = mysql_connect('localhost','root','','ninja') or die("Error 1");''? * *
- !
...
-
24th January 2013 16:49 #5
Code:class DB { private static $singleton; private $dbObject; protected function __construct() { $this->dbObject = new mysqli($MYSQL_IP, 'user', 'pass'); } public static function instance() { if(!(self::$singleton instanceof self)) { self::$singleton = new self(); self::query("SET NAMES 'utf8'"); self::get()->set_charset('utf8'); } return self::$singleton; } public static function get() { return self::instance()->dbObject; } public static function query($qry){ $result = self::get()->query($qry); if($result){ $data = array(); if (!is_object($result)) return $data; if ($result->num_rows > 0) { while ($row = $result->fetch_assoc()){ $data[] = $row; } } $result->close(); return $data; } else return false; } public static function escape($str) { return self::get()->real_escape_string($str); } }
-
24th January 2013 17:00 #6
, ...

, singleton ?
, self(), - static().
, ...
.
,
..




Reply With Quote
Lenovo ThinkPad 15 IdeaPad 15
5th May 2023, 22:16 in