Ho appena vedere questa articePHP vs MySQL Performance (se, funzioni) nella query
ho bisogno di sapere cosa c'è è meglio berformance in questi casi
se statment nella query
SELECT *,if(status = 1 , "active" ,"unactive") as status_val FROM comments
VS
<?php
$x = mysql_query("SELECT * FROM comments");
while($res = mysql_fetch_assoc($x)){
if($x['status'] == 1){
$status_val = 'active';
}else{
$status_val = 'unactive';
}
}
?>
Cut 10 da stringa
SELECT * , SUBSTR(comment, 0, 10) as min_comment FROM comments
VS
<?php
$x = mysql_query("SELECT * FROM comments");
while($res = mysql_fetch_assoc($x)){
$min_comment = substr($x['comment'],0,10) ;
}
?>
ecc ????? e Quando utilizzo le funzioni MYSQL o le funzioni PHP?
Puoi testarlo con microtime. Ma questo è un eccesso di ottimizzazione e il miglioramento della velocità sarà molto piccolo ... La maggior parte delle volte non selezioni grandi set di risultati da db –
[** Per favore, non usare le funzioni 'mysql_ *' nel nuovo codice **] (http://bit.ly/phpmsql). Non sono più mantenuti e il [processo di deprecazione] (http://j.mp/Rj2iVR) è iniziato su di esso. Vedi la [** red box **] (http://j.mp/Te9zIL)? Scopri invece [* prepared statements *] (http://j.mp/T9hLWi), e usa [PDO] (http://php.net/pdo) o [MySQLi] (http://php.net/ mysqli) - [questo articolo] (http://j.mp/QEx8IB) ti aiuterà a decidere quale. Se scegli PDO, [ecco un buon tutorial] (http://j.mp/PoWehJ). –