You are on page 1of 2
same PP Ganga gee leat SOL. Mid ‘Session Extensions Text Processing Variable and Type Related Extensions ‘Web Services ‘aly Ext XML Manipulation Keyboard Shortcuts *isttp [Next menuitem Previous menu item Provious man page Next man page Serol to bottom ne Serol top gh Goto homepage gs Goto search ‘current page) Focus search box Funciones de MvSOL » sEjemplos Manual de PHP Roferencia de funcione Extensions dba Extensiones de bases de datos especifices del proveedor MySOL MYSOL (Original Hiemplo ‘Change language: Seas : HiRes Ejemplo general de la extensién MySQL 4, [Este simple ejemplo muestra como conectar, ejecutar usa consulta, imprimir as filasresultantes y desconectar a una base de datos MySQL. Ejemplo #1 Bjemplo pencral de la extensidn MySQL. Hi Conactardo, selecciorando 1a base de datos ‘Link = mysel_connect(°nysai_host's ‘nysa_user’s ‘mysqi_password") ‘or die("No se pudo conectan: "". mys@lierror()): echo ‘Connected suecessfully's rysa_select dB(A database’) or die(‘No se pido selecctonar 2a base de datos"); 1) Roatizar una consult MySQh Sauery = "SELECT * FROM my-table's Sresult = aysal_query($query) or diet ‘Consulta fatlida: 11 imprinse tos resultados en HIML cho "etab100\0"5 inte ($line = mys echo “\eceea ns foreach ($1ine as $col_value) { echo "\e\tetabfeol_valuecst@>\e fetch sy(Sresule, MYSQL_ASSOC)) ( ? eno “\eestea\nts > eho “stable ver: 1) Aiberan resultados rysal_free_resule(Sresult); 11 Concur 2a conextn rysh_close($1ink); User Contributed Notes 1 note eee nemanatanalnmpey same PP Ganga gee leat SOL. Mid a down 2 ‘wf at 163 dot com year ago fae auare that 4 you are trying to foreach the assoclative array returned by aysal_fetch_array() with MYSQL_ASSOC or mysql_fetch_ass0c(), you have to ensure the return value that is used in foreach structure is exactly a array rather than & FALSE valve, fr you night encounter the warning below Warning: Invalid argunent susplies “or foreach() ere £5 an exanple (assume that Srasult have already stored the retuen value fron aysgl_query()) 16 you have sone block of code Tike: ohp 11 ageing resus tn HTML cho "etableo\n"s sie (Sline » mysql fetch arnay(Soesule, HYSQL_ASSOC)) ( echo “\eceen ns ‘Foreach (Shine as $col_vaiue) { echo "\e\teean$eol_valuee/ tables } eno estrone > eho “stable ert 1 this 4s the case, you should use the code below insteas: 11 check ahead, before using st 1 (aysal_non_rows(Sresult) > 0) { 11 Pointing results te MIM, eho “tablen\e"; inte (Stine = 995 echo "tears foreach ($line as $col_value) { echo "\e\teted Sol valuec/t\n"; fch_arrayt$rosunt, MYSQL_ASSOC)) ¢ > cho "\tesero\n"s : echo “e/tabler\n"s + Copuright © 2001-2016 The PHP Group + MyPHPnet Contact + Other PHPt sites + Minor sites + Privacy policy eee nemanatanalnmpey

You might also like