From 641729d204e9eb372a5a997d23385f2b3cb31f8b Mon Sep 17 00:00:00 2001 From: Daniel Convissor Date: Fri, 13 Mar 2009 00:16:11 +0000 Subject: [PATCH] * Provide OOP example when extending mysqli class. * Adjust examples to match other connect examples. * Check for errors along the way. git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@277081 c90b9560-bf6c-de11-be94-00142212c4b1 --- reference/mysqli/mysqli/real-connect.xml | 99 ++++++++++++++++-------- 1 file changed, 68 insertions(+), 31 deletions(-) diff --git a/reference/mysqli/mysqli/real-connect.xml b/reference/mysqli/mysqli/real-connect.xml index 04bf244c01..1f8d71b2a5 100644 --- a/reference/mysqli/mysqli/real-connect.xml +++ b/reference/mysqli/mysqli/real-connect.xml @@ -1,5 +1,5 @@ - + mysqli::real_connect @@ -199,26 +199,62 @@ options(MYSQLI_INIT_COMMAND, "SET AUTOCOMMIT=0"); -$mysqli->options(MYSQLI_OPT_CONNECT_TIMEOUT, 5); - -/* connect to server */ -$mysqli->real_connect('localhost', 'my_user', 'my_password', 'world'); - -/* check connection */ -if (mysqli_connect_errno()) { - printf("Connect failed: %s\n", mysqli_connect_error()); - exit(); +if (!$mysqli) { + die('mysqli_init failed'); } -printf ("Connection: %s\n.", $mysqli->host_info); +if (!$mysqli->options(MYSQLI_INIT_COMMAND, 'SET AUTOCOMMIT = 0')) { + die('Setting MYSQLI_INIT_COMMAND failed'); +} + +if (!$mysqli->options(MYSQLI_OPT_CONNECT_TIMEOUT, 5)) { + die('Setting MYSQLI_OPT_CONNECT_TIMEOUT failed'); +} + +if (!$mysqli->real_connect('localhost', 'my_user', 'my_password', 'my_db')) { + die('Connect Error (' . mysqli_connect_errno() . ') ' + . mysqli_connect_error()); +} + +echo 'Success... ' . $mysqli->host_info . "\n"; $mysqli->close(); ?> +]]> + + + + Object oriented style when extending mysqli class + +host_info . "\n"; + +$db->close(); +?> ]]> @@ -228,23 +264,25 @@ $mysqli->close(); @@ -254,8 +292,7 @@ mysqli_close($link); &example.outputs;