note 73840 added to function.mysqli-query

From: Date: Mon, 12 Mar 2007 18:55:45 +0000
Subject: note 73840 added to function.mysqli-query
Groups: php.notes 
Request: Send a blank email to php-notes+get-124384@lists.php.net to get a copy of this message
this is a variant of mysqli_query that returns output parameters as a rowset. <?php function mysqli_exec($link, $command) { $select = ''; $i2 = 0; while (true) { $i1 = strpos($command, '@', $i2); if ($i1 === false) break; $field = ''; $i2 = $i1 + 1; while ($i2 < strlen($command) && ($command[$i2] >= '0' && $command[$i2] <= '9') || ($command[$i2] >= 'A' && $command[$i2] <= 'Z') || ($command[$i2] >= 'a' && $command[$i2] <= 'z') || ($command[$i2] == '_')) $i2++; $field = substr($command, $i1 + 1, $i2 - $i1 - 1); if (strlen($select) == 0) $select = "select @{$field} as $field"; else $select = $select . ", @{$field} as $field"; } if (strlen($select) > 0) { mysqli_query($link, $command); return mysqli_query($link, $select); } else return mysqli_query($link, $command); } ?> an example: <?php $link = mysqli_connect('localhost', 'myusr', 'mypass') or die ('Error connecting to mysql: ' . mysqli_error($link)); mysqli_select_db($link, 'clips'); $user_name = 'test'; $result = mysqli_exec($link, "call do_user_login('$user_name', @session_id, @msg)"); while ($row = mysqli_fetch_assoc($result)) { echo "session_id : {$row['session_id']} <br>"; echo "msg : {$row['msg']} <br>"; } ?> ---- Server IP: 200.59.45.3 Probable Submitter: 200.1.117.15 (proxied: 1.1 SIDWPX01) ---- Manual Page -- http://www.php.net/manual/en/function.mysqli-query.php Edit -- https://master.php.net/note/edit/73840 Del: integrated -- https://master.php.net/note/delete/73840/integrated Del: useless -- https://master.php.net/note/delete/73840/useless Del: bad code -- https://master.php.net/note/delete/73840/bad+code Del: spam -- https://master.php.net/note/delete/73840/spam Del: non-english -- https://master.php.net/note/delete/73840/non-english Del: in docs -- https://master.php.net/note/delete/73840/in+docs Del: other reasons-- https://master.php.net/note/delete/73840 Reject -- https://master.php.net/note/reject/73840 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#124384) next »