note 100999 added to function.mysql-query

From: Date: Fri, 19 Nov 2010 11:42:30 +0000
Subject: note 100999 added to function.mysql-query
Groups: php.notes 
Request: Send a blank email to php-notes+get-174181@lists.php.net to get a copy of this message
<?php public function mysqlRead ( $table = null , $what = null , $where = null , $equalsTo = null , $orderBy = null , $type = null ) //@ { $connect = self::mysqlConnect(); if ( $table !== null && $what !== null && $where !== null && $equalsTo !== null ) { if ( $orderBy !== null && $type !== null ) { $query = "SELECT $what FROM $table WHERE $where = \"$equalsTo\" ORDER BY $orderBy $type"; } else { $query = "SELECT $what FROM $table WHERE $where = \"$equalsTo\""; } $query = mysql_query ( $query , $connect ); $row = mysql_num_rows ( $query ); if ( $row ) { $i = 0; while ( $result[] = mysql_fetch_array ( $query ) ) { $i++; } unset ( $result[count($result)-1] ); //Fixes the last "ghost" index return $result; } else { return false; } return $result; } else if ( $table !== null && $what !== null && $where !== null && $equalsTo == null ) { if ( is_array ( $where ) ) { $container = ""; $contar = count ( $where ) -1; $i = 0; foreach ( $where as $key => $val ) { if ( $i != $contar ) { $container .= $key . " = \"" . $val . "\" AND "; } else { $container .= $key . " = \"" . $val . "\""; } $i++; } } else { return false; } if ( $orderBy !== null && $type !== null ) { $query = "SELECT $what FROM $table WHERE $container ORDER BY $orderBy $type"; } else { $query = "SELECT $what FROM $table WHERE $container"; } $query = mysql_query ( $query , $connect ); $row = mysql_num_rows ( $query ); if ( $row ) { $i = 0; while ( $result[] = mysql_fetch_array ( $query ) ) { $i++; } unset ( $result[count($result)-1] ); //Fixes the last "ghost" index return $result; } else { return false; } return $result; } else if ( $table !== null && $what !== null ) { if ( $orderBy !== null && $type !== null ) { $query = "SELECT $what FROM $table ORDER BY $orderBy $type"; } else { $query = "SELECT $what FROM $table"; } $query = mysql_query ( $query , $connect ); $row = mysql_num_rows ( $query ); if ( $row ) { $i = 0; while ( $result[] = mysql_fetch_array ( $query ) ) { $i++; } unset ( $result[count($result)-1] ); //Fixes the last "ghost" index return $result; } else { return false; } } else { return false; } self::mysqlClose ( $connect ); } ?> ---- Server IP: 194.8.30.16 Probable Submitter: 85.240.148.90 ---- Manual Page -- http://www.php.net/manual/en/function.mysql-query.php Edit -- https://master.php.net/note/edit/100999 Del: integrated -- https://master.php.net/note/delete/100999/integrated Del: useless -- https://master.php.net/note/delete/100999/useless Del: bad code -- https://master.php.net/note/delete/100999/bad+code Del: spam -- https://master.php.net/note/delete/100999/spam Del: non-english -- https://master.php.net/note/delete/100999/non-english Del: in docs -- https://master.php.net/note/delete/100999/in+docs Del: other reasons-- https://master.php.net/note/delete/100999 Reject -- https://master.php.net/note/reject/100999 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#174181) next »