Php Procedimientos Al

download Php Procedimientos Al

of 34

Transcript of Php Procedimientos Al

  • 8/3/2019 Php Procedimientos Al

    1/34

    Funciones de MySQL

    Notas

    Note:

    Muchas funciones de MySQL aceptan link_identifiercomo ltimo parmetro. Si no

    se proviene, se utilizar la ltima conexin abierta. Si esta no existe, se intentar

    establecer conexin con el parmetro predeterminado definido en php.ini. Si no hay

    xito, las funciones devuelven FALSE

    Table of Contents

    mysql_affected_rowsObtiene el nmero de filas afectadas en la anterioroperacin de MySQL

    mysql_client_encodingDevuelve el nombre de la coleccin de caracteres mysql_closeCierra la conexin de MySQL mysql_connectAbre una conexin al servidor MySQL mysql_create_dbCrea una base de datos MySQL mysql_data_seekMueve el apuntador interno del resultado mysql_db_nameObtiene los datos del resultado mysql_db_queryEnva una consulta MySQL mysql_drop_dbOmite (elimina) una base de datos MySQL mysql_errnoDevuelve un mensaje de error con un valor numrico de la

    operacin anterior con MySQL

    mysql_error

    Devuelve el texto con error del mensaje de la anterior operacin

    MySQL

    mysql_escape_stringEscapa una cadena para ser usada en mysql_query mysql_fetch_arrayRecupera una fila de resultado como un array asociativo,

    un array numrico o como ambos

    mysql_fetch_assocRecupera una fila de resultado como un array asociativo mysql_fetch_fieldObtiene la informacin de una columna desde un resultado

    y la devuelve como un objeto

    mysql_fetch_lengthsObtiene la longitud de cada salida en un resultado mysql_fetch_objectRecupera una fila de resultado como un array objeto

    mysql_fetch_row

    Recupera una fila de resultado como un array numrico mysql_field_flagsObtiene los flags asociados con el campo especificado en

    un resultado

    mysql_field_lenDevuelve la longitud del campo especificado mysql_field_nameObtiene el nombre del campo especificado en un resultado mysql_field_seekEstablece el apuntador del resultado en un nmero de

    campo especficado

    mysql_field_tableObtiene el nombre de la tabla en la que est el campoespecificado

    mysql_field_typeObtiene el tipo del campo especificado en un resultado mysql_free_resultLibera la memoria del resultado mysql_get_client_info

    Obtener informacin del cliente MySQL

    mysql_get_host_infoObtener informacin de la mquina anfitriona MySQL

    http://mx.php.net/manual/es/function.mysql-affected-rows.phphttp://mx.php.net/manual/es/function.mysql-affected-rows.phphttp://mx.php.net/manual/es/function.mysql-client-encoding.phphttp://mx.php.net/manual/es/function.mysql-client-encoding.phphttp://mx.php.net/manual/es/function.mysql-close.phphttp://mx.php.net/manual/es/function.mysql-close.phphttp://mx.php.net/manual/es/function.mysql-connect.phphttp://mx.php.net/manual/es/function.mysql-connect.phphttp://mx.php.net/manual/es/function.mysql-create-db.phphttp://mx.php.net/manual/es/function.mysql-create-db.phphttp://mx.php.net/manual/es/function.mysql-data-seek.phphttp://mx.php.net/manual/es/function.mysql-data-seek.phphttp://mx.php.net/manual/es/function.mysql-db-name.phphttp://mx.php.net/manual/es/function.mysql-db-name.phphttp://mx.php.net/manual/es/function.mysql-db-query.phphttp://mx.php.net/manual/es/function.mysql-db-query.phphttp://mx.php.net/manual/es/function.mysql-drop-db.phphttp://mx.php.net/manual/es/function.mysql-drop-db.phphttp://mx.php.net/manual/es/function.mysql-errno.phphttp://mx.php.net/manual/es/function.mysql-errno.phphttp://mx.php.net/manual/es/function.mysql-error.phphttp://mx.php.net/manual/es/function.mysql-error.phphttp://mx.php.net/manual/es/function.mysql-escape-string.phphttp://mx.php.net/manual/es/function.mysql-escape-string.phphttp://mx.php.net/manual/es/function.mysql-fetch-array.phphttp://mx.php.net/manual/es/function.mysql-fetch-array.phphttp://mx.php.net/manual/es/function.mysql-fetch-assoc.phphttp://mx.php.net/manual/es/function.mysql-fetch-assoc.phphttp://mx.php.net/manual/es/function.mysql-fetch-field.phphttp://mx.php.net/manual/es/function.mysql-fetch-field.phphttp://mx.php.net/manual/es/function.mysql-fetch-lengths.phphttp://mx.php.net/manual/es/function.mysql-fetch-lengths.phphttp://mx.php.net/manual/es/function.mysql-fetch-object.phphttp://mx.php.net/manual/es/function.mysql-fetch-object.phphttp://mx.php.net/manual/es/function.mysql-fetch-row.phphttp://mx.php.net/manual/es/function.mysql-fetch-row.phphttp://mx.php.net/manual/es/function.mysql-field-flags.phphttp://mx.php.net/manual/es/function.mysql-field-flags.phphttp://mx.php.net/manual/es/function.mysql-field-len.phphttp://mx.php.net/manual/es/function.mysql-field-len.phphttp://mx.php.net/manual/es/function.mysql-field-name.phphttp://mx.php.net/manual/es/function.mysql-field-name.phphttp://mx.php.net/manual/es/function.mysql-field-seek.phphttp://mx.php.net/manual/es/function.mysql-field-seek.phphttp://mx.php.net/manual/es/function.mysql-field-table.phphttp://mx.php.net/manual/es/function.mysql-field-table.phphttp://mx.php.net/manual/es/function.mysql-field-type.phphttp://mx.php.net/manual/es/function.mysql-field-type.phphttp://mx.php.net/manual/es/function.mysql-free-result.phphttp://mx.php.net/manual/es/function.mysql-free-result.phphttp://mx.php.net/manual/es/function.mysql-get-client-info.phphttp://mx.php.net/manual/es/function.mysql-get-client-info.phphttp://mx.php.net/manual/es/function.mysql-get-host-info.phphttp://mx.php.net/manual/es/function.mysql-get-host-info.phphttp://mx.php.net/manual/es/function.mysql-get-host-info.phphttp://mx.php.net/manual/es/function.mysql-get-client-info.phphttp://mx.php.net/manual/es/function.mysql-free-result.phphttp://mx.php.net/manual/es/function.mysql-field-type.phphttp://mx.php.net/manual/es/function.mysql-field-table.phphttp://mx.php.net/manual/es/function.mysql-field-seek.phphttp://mx.php.net/manual/es/function.mysql-field-name.phphttp://mx.php.net/manual/es/function.mysql-field-len.phphttp://mx.php.net/manual/es/function.mysql-field-flags.phphttp://mx.php.net/manual/es/function.mysql-fetch-row.phphttp://mx.php.net/manual/es/function.mysql-fetch-object.phphttp://mx.php.net/manual/es/function.mysql-fetch-lengths.phphttp://mx.php.net/manual/es/function.mysql-fetch-field.phphttp://mx.php.net/manual/es/function.mysql-fetch-assoc.phphttp://mx.php.net/manual/es/function.mysql-fetch-array.phphttp://mx.php.net/manual/es/function.mysql-escape-string.phphttp://mx.php.net/manual/es/function.mysql-error.phphttp://mx.php.net/manual/es/function.mysql-errno.phphttp://mx.php.net/manual/es/function.mysql-drop-db.phphttp://mx.php.net/manual/es/function.mysql-db-query.phphttp://mx.php.net/manual/es/function.mysql-db-name.phphttp://mx.php.net/manual/es/function.mysql-data-seek.phphttp://mx.php.net/manual/es/function.mysql-create-db.phphttp://mx.php.net/manual/es/function.mysql-connect.phphttp://mx.php.net/manual/es/function.mysql-close.phphttp://mx.php.net/manual/es/function.mysql-client-encoding.phphttp://mx.php.net/manual/es/function.mysql-affected-rows.php
  • 8/3/2019 Php Procedimientos Al

    2/34

    mysql_get_proto_infoObtener informacin del protocolo MySQL mysql_get_server_infoObtener informacin del servidor MySQL mysql_infoObtiene informacin sobre la consulta ms reciente mysql_insert_idObtiene la ID generada en la ltima consulta mysql_list_dbsLista de las bases de datos disponibles en un servidor MySQL mysql_list_fields

    Lista los campos del resultado de MySQL

    mysql_list_processesLista los procesos MySQL mysql_list_tablesLista las tablas de una base de datos MySQL mysql_num_fieldsObtiene el nmero de campos en un resultado mysql_num_rowsObtener el nmero de filas de un resultset mysql_pconnectAbre una conexin persistente a un servidor MySQL mysql_pingEfectuar un chequeo de respuesta (ping) sobre una conexin de

    servidor o reconectarse si no hay conexin

    mysql_queryEnviar una consulta MySQL mysql_real_escape_stringEscapa caracteres especiales en una cadena para

    ser usado en una sentencia SQL

    mysql_result

    Obtener datos de resultado mysql_select_dbSeleccionar una base de datos MySQL mysql_set_charsetEstablece el conjunto de caracteres del cliente mysql_statObtiene el status actual del sistema mysql_tablenameObtiene el nombre de la tabla de un campo mysql_thread_idDevuelve el ID del hilo actual mysql_unbuffered_queryEnva una consulta SQL a MySQL, sin recuperar ni

    colocar en bfer las filas de resultado

    mysql_affected_rows Ejemplo general de la extensin MySQL

    Last updated: Fri, 27 May 2011

    add a noteUser Contributed NotesFunciones de MySQLVladimir Kosmala27-Oct-2010 09:57Here a mysql helper containing the main functions of the mysqlextension. It's easy to understand for a beginner and quite usefulbecause queries are secure. It understands what you want, just writeyour sql query. I called it mysql_magic.

  • 8/3/2019 Php Procedimientos Al

    3/34

    $narg = func_num_args();$args = func_get_args();

    if (!$dblink){

    $dblink = mysql_connect( $sqlhost, $sqluser, $sqlpass );

    mysql_select_db( $sqlbase, $dblink );}

    $req_sql = array_shift($args);$req_args = $args;

    $req_query = mysql_bind($req_sql, $req_args);$req_result = mysql_query($req_query);

    if (!$req_result){

    trigger_error(mysql_error());return false;

    }

    if (startsWith($req_sql, 'delete') || startsWith($req_sql,'update'))

    {return mysql_affected_rows(); // -1 || N

    }else if (startsWith($req_sql, 'insert')){

    return mysql_insert_id(); // ID || 0 || FALSE}else if (endsWith($req_sql, 'limit 1')){

    return mysql_fetch_assoc($req_result); // [] || FALSE}else if (startsWith($req_sql, 'select count(*)')){

    $line = mysql_fetch_row($req_result);return $line[0]; // N

    }else{

    return mysql_fetch_all($req_result); // [][]}

    }

    function mysql_bind($sql, $values=array())

    {foreach ($values as &$value) $value =

    mysql_real_escape_string($value);$sql = vsprintf( str_replace('?', "'%s'", $sql), $values);return $sql;

    }

    function mysql_fetch_all($result){

    $resultArray = array();while(($resultArray[] = mysql_fetch_assoc($result)) ||

    array_pop($resultArray));return $resultArray;

    }

  • 8/3/2019 Php Procedimientos Al

    4/34

    function startsWith($haystack,$needle,$case=false) {if($case){return (strcmp(substr($haystack, 0,

    strlen($needle)),$needle)===0);}return (strcasecmp(substr($haystack, 0,

    strlen($needle)),$needle)===0);}

    function endsWith($haystack,$needle,$case=false) {if($case){return (strcmp(substr($haystack, strlen($haystack) -

    strlen($needle)),$needle)===0);}return (strcasecmp(substr($haystack, strlen($haystack) -

    strlen($needle)),$needle)===0);}?>

    Don't forget to set $sqlhost, $sqluser, $sqlpass and $sqlbase.

    With help of :mysql_bind :http://php.net/manual/en/function.mysql-real-escape-string.php#96391mysql_fetch_all :http://php.net/manual/en/function.mysql-fetch-assoc.php#90030

    trigger_error may be enhanced with this tip :http://php.net/manual/en/function.trigger-error.php#98910

    Chris Parsons29-May-2009 10:36Here is a function for preventing a MySQL query timeout.

    Add a temporary table to the database:

    CREATE TABLE `temp_table` (`ID` DOUBLE ,

    `temp` BLOB);

    Call this function in every iteration of any long loops in your code(it will only be run at a maximum once every 15 seconds, regardless ofhow often the function is called):

  • 8/3/2019 Php Procedimientos Al

    5/34

    }?>

    MySQL has multiple timeout counters, one for inserts, and one fordeletes, and I could not find a way to extend them in PHP. Pleasenote that this is a different issue entirely than the 'connect'

    timeout. Every 15 seconds, this function will insert, select, anddelete a row from the temporary table, thus preventing a querytimeout.

    Good Luck!

    joachimb at gmail dot com16-May-2008 04:28Lazy Man's Logging:

  • 8/3/2019 Php Procedimientos Al

    6/34

    # 1) Structure of both tables should be same.# 2) Name of both table should be different but if same than obviously# second table should be if different database.# 3) If use two database than both database permission should be same# as i am using aliases to get the information.#

    # USES::# 1) This may be useful when you did some changes in your existing# script and you expect the certain output. So with the help of this# function you may compare the impact due to your changes inscript.##

    $host=""; # host name or ip address$user=""; # database user name$pass=""; # database password$database=""; # dateabase name with which you want to connect

    # get connection with mysql$dblink = @mysql_connect($host,$user,$pass);

    # select and open databasemysql_select_db($database,$dblink);

    $db1="< your db1 >"; // first database// second database if database are same for both tables than use thesame as db1$db2="< your db2 >";$table1="< your table1 >"; // first table// second table if database is same for both tables than table name# must be different but fields name are same and order of the fieldsare same.

    $table2="< your table2 >";

    // function starts herefunction table_data_difference($first,$second){

    global $dblink;$sql1 = "SHOW FIELDS FROM $first";$result = mysql_query($sql1,$dblink) or die("Having error in

    execution 1 ==".mysql_error());

    while($row = mysql_fetch_object($result)){

    $from_fields[]=$row->Field;}

    $sql="select * from $first";$res=mysql_query($sql,$dblink) or die("Having error in execution

    2==".mysql_error());$j=1;while($row=mysql_fetch_array($res)){

    $num=count($from_fields);

    $sql_next="select $second.* from $second where";

    for($i=0;$i < $num;$i++)

  • 8/3/2019 Php Procedimientos Al

    7/34

    {$sql_next=$sql_next."

    ".$second.".".$from_fields[$i]."='".$row[$from_fields[$i]]."' and ";}

    $sql_next=substr($sql_next,0,strlen($sql_next)-5);

    $res_next=mysql_query($sql_next,$dblink) or die("Having errorin execution 3==".mysql_error());

    $num1=mysql_num_rows($res_next);if($num1==0){

    for($i=0;$i < count($from_fields);$i++){

    $val=$val."
    ".$from_fields[$i]."=".$row[$from_fields[$i]];}// Display the record which are not matched.echo "
    \n".$j.".".$val;echo "
    ------------------------------------------------

    -----";$j++;

    }

    }

    }

    $first=$db1.'.'.$table1;$second=$db2.'.'.$table2;

    table_data_difference($first,$second);

    ?>

    matiyahoo-publico at yhoo dot com dot ar17-Nov-2007 10:26David:

    In this line:

    $query = "SELECT username FROM users WHERE username REGEXP'$username[0-9*]'";

    PHP may read $username[, *including* the open square bracket, and maythink you are trying to get into an array.

    You should use this instead:

    $query = "SELECT username FROM users WHERE username REGEXP'${username}[0-9*]'";

    Or maybe this:

    $query = "SELECT username FROM users WHERE username REGEXP '$username". "[0-9*]'";

    david at kiwi dot com09-Nov-2007 10:13I am wanting to increment usernames which are to be alphabeticcharacters A-Z or a-z and if someone uses "abc" it will automaticallybe given "abc1" and the next applicant to apply for that same username

    will automatically be given "abc2", the next "abc3" and so on. If Ienter the following into MySQL;

    http://mx.php.net/manual/es/ref.mysql.php#79260http://mx.php.net/manual/es/ref.mysql.php#79260http://mx.php.net/manual/es/ref.mysql.php#79260http://mx.php.net/manual/es/ref.mysql.php#79082http://mx.php.net/manual/es/ref.mysql.php#79082http://mx.php.net/manual/es/ref.mysql.php#79082http://mx.php.net/manual/es/ref.mysql.php#79082http://mx.php.net/manual/es/ref.mysql.php#79260
  • 8/3/2019 Php Procedimientos Al

    8/34

    SELECT username FROM users WHERE username REGEXP 'abc[0-9*]';

    the result is

    abc1abc2

    abc3

    I have been given the following script from another forum but it doesnot work;

  • 8/3/2019 Php Procedimientos Al

    9/34

    to be available to the Windows systems PATH.

    Following PHP Script is useful to test PHP connection with MySQL.*/

    //$connect = mysql_connect("Your Host Name", "MySQL root directory",

    'MySQL password, if any');//$connect = mysql_connect("Host Name or Address - 127.0.0.1", "root",'password');$connect = mysql_connect("localhost", "root", 'password');if ($connect){echo "Congratulations!\n
    ";echo "Successfully connected to MySQL database server.\n
    ";}else{$error = mysql_error();echo "Could not connect to the database. Error = $error.\n
    ";exit();}

    // Closing connection$close = mysql_close($connect);if ($close){echo "\n
    ";echo "Now closing the connection...\n
    ";echo "MySQL connection closed successfully as well.\n
    ";}else{echo "There's a problem in closing MySQL connection.\n
    ";}exit();?>

    rad14701 at yahoo dot com14-Oct-2007 02:01@Amanda 12-Oct-2007 09:58

    I almost had to ask myself if this was a real question... If the MySQLserver rejects the connection attempt then, yes, MySQL would be ableto send back an error to PHP... And if PHP can't access the targetMySQL server at all then it is also smart enough to issue theappropriate error all by itself...

    arnold_dba13-Oct-2007 08:36Also, to secure MySQL data and to be able to comply with PCIstandards, you should encrypt the data. There are many ways to do it.For hackers, you can use dm-crypt (www.saout.de/misc/dm-crypt) tool.It is basically used to encrypt the whole partition. If you want asophisticated solution go with Security-GENERAL for MySQL from packetgeneral (www.packetgeneral.com)

    On windows, you can use disk encryption feature provided by windowsitself or tool like trucrypt (www.truecrypt.org)

    DuiMDog02-Sep-2007 05:19On 11-Apr-2007 admin at mihalism dot com posted an 'easy to use MySql-class'.In my opinion there is a bug in the get_affected_rows-function. Itrefers to query-id, but it should refer to connect-id instead.

    The corrected function should be:function get_affected_rows($connect_id = ""){

    if($connect_id == NULL){$return = mysql_affected_rows($this->connect_id);

    }else{

    $return = mysql_affected_rows($connect_id);}if(!$return){

    http://mx.php.net/manual/es/ref.mysql.php#78486http://mx.php.net/manual/es/ref.mysql.php#78486http://mx.php.net/manual/es/ref.mysql.php#78486http://mx.php.net/manual/es/ref.mysql.php#78467http://mx.php.net/manual/es/ref.mysql.php#78467http://mx.php.net/manual/es/ref.mysql.php#78467http://mx.php.net/manual/es/ref.mysql.php#77528http://mx.php.net/manual/es/ref.mysql.php#77528http://mx.php.net/manual/es/ref.mysql.php#77528http://mx.php.net/manual/es/ref.mysql.php#77528http://mx.php.net/manual/es/ref.mysql.php#78467http://mx.php.net/manual/es/ref.mysql.php#78486
  • 8/3/2019 Php Procedimientos Al

    10/34

    $this->error();}else{

    return $return;}

    }

    atk2 at hotmail dot com14-Jun-2007 10:56

    After finally getting IIS, PHP, and MySQL on a new Windows XP machine,I decided to write the steps I took so you can see how it was done:http://www.atksolutions.com/articles/install_php_mysql_iis.html

    Hope this helps.

    tomasz dot rup at gmail dot com16-Apr-2007 06:14Correct algorithm to generate MySQL password hash is:

    Nobody Special14-Apr-2007 01:20This PHP5-only class is used so that $db isn't passed. Kudos to arjenat queek dot nl for example.

  • 8/3/2019 Php Procedimientos Al

    11/34

    $fetch = $db->fetch_array($query);print_r($fetch);?>

    mega-squall at caramail dot com13-Apr-2007 04:35For Windows users, please note:

    If apache is installed as a service, and you change PATH variable soit can reach libmysql.dll, you will need to reboot your machine inorder to have changes applied.

    admin at mihalism dot com11-Apr-2007 09:48Heres a easy to use MySQL class for any website

  • 8/3/2019 Php Procedimientos Al

    12/34

    }//+======================================================+function fetch_row($query_id = ""){

    if($query_id == NULL){$return = mysql_fetch_array($this->query_result);

    }else{

    $return = mysql_fetch_array($query_id);}if(!$return){

    $this->error();}else{

    return $return;}

    }//+======================================================+function get_affected_rows($query_id = ""){

    if($query_id == NULL){$return = mysql_affected_rows($this->query_result);

    }else{$return = mysql_affected_rows($query_id);

    }if(!$return){

    $this->error();}else{

    return $return;}

    }//+======================================================+function sql_close(){

    if($this->connect_id){return mysql_close($this->connect_id);

    }}//+======================================================+

    }

    /* Example */

    $DB = new mysql_db();$DB->sql_connect('sql_host', 'sql_user', 'sql_password',

    'sql_database_name');$DB->query("SELECT * FROM `members`");$DB->sql_close();

    ?>

    26-Jan-2007 03:14Note, that the sql.safe_mode configuration setting does effect allmysql_* functions. This has nothing to to with the php safe mode,check the [SQL] section in php.ini.

    I found out, that if you set sql.safe_mode = On, mysql_connect willignore provided username and passwort and makes use of the scriptowner instead (checked on debian).

    ravenal at uniphix dot com27-Nov-2006 04:37I was working with a friend of mine and he happened wanted to sortdata based on the column names, well this function will basically sortthe Field Names in ABC order and then from there on it'll add the databased on the field names assigned to...

    You can use this to create easily forms and exclude what you don'twant to be as entered data or sort it based on what order you want...

    http://mx.php.net/manual/es/ref.mysql.php#72632http://mx.php.net/manual/es/ref.mysql.php#72632http://mx.php.net/manual/es/ref.mysql.php#71411http://mx.php.net/manual/es/ref.mysql.php#71411http://mx.php.net/manual/es/ref.mysql.php#71411http://mx.php.net/manual/es/ref.mysql.php#71411http://mx.php.net/manual/es/ref.mysql.php#72632
  • 8/3/2019 Php Procedimientos Al

    13/34

  • 8/3/2019 Php Procedimientos Al

    14/34

    $newarray[$v] = $array[$v];

    foreach( $array AS $index => $val2 ){

    if( in_array($index, $sortfirst ) )continue;

    $newarray[$index] = $val2;}

    $array = $newarray;}

    }

    if( $exclude ){

    if( is_array($exclude) ){

    $out = array();

    foreach( $array AS $index2 => $val2 ){

    if( in_array( $index2, $exclude ) )continue;

    $out[$index2] = $val2;}

    $array = $out;}

    }

    return $array;}?>

    mdhafen at x.washk12.org19-Oct-2006 01:00In response to martijn at elicit dot nl

    Actually it is possible as a query, even with an auto_increment keyfield. Like so...

    INSERTINTOtablename( list, of, ALL, similar, columns )

    ( SELECT*

    FROMtablename

    WHEREsomefield = 'somevalue' )

    That should work.

    martijn at elicit dot nl29-Aug-2006 02:52Keeping history records usually requires you to duplicate rows. Withstandard MySQL syntax you can create a query like this:

    INSERT

    INTOtablenameSELECT

    http://mx.php.net/manual/es/ref.mysql.php#70526http://mx.php.net/manual/es/ref.mysql.php#70526http://mx.php.net/manual/es/ref.mysql.php#70526http://mx.php.net/manual/es/ref.mysql.php#69256http://mx.php.net/manual/es/ref.mysql.php#69256http://mx.php.net/manual/es/ref.mysql.php#69256http://mx.php.net/manual/es/ref.mysql.php#69256http://mx.php.net/manual/es/ref.mysql.php#70526
  • 8/3/2019 Php Procedimientos Al

    15/34

    *FROM

    tablenameWHERE

    somefield = 'somevalue'

    The problem is that this won't work if you are using an auto_numberingkey id field. There is no way to do this with standard MySQL syntaxand I haven't been able to find a standard php function as well. Sohere's the function I wrote for that very purpose:

    davesteinb at yahoo dot com13-Aug-2006 05:32I made this function to reduce DB calls. You can store Mysql resultsin a session var and sort the results on any column. Might work nicein an AJAX app.

  • 8/3/2019 Php Procedimientos Al

    16/34

    $temp_array = array();$i=0;foreach ($results as $res) {

    $temp_array[$i] = $res[$sort_field];$i++;

    }

    if ($dir=="ASC") {asort($temp_array);} else {

    arsort($temp_array);}

    $new_results = array();$i=0;foreach($temp_array as $k => $v) {

    $new_results[$i] = $results[$k];$i++;

    }ksort($new_results);return $new_results;

    }

    //useif (count($_SESSION["res"])==0) {

    $_SESSION["res"] = [GET DATABASE RESULTS HOWEVER YOU MAY]}

    $_SESSION["res"] = mysql_sort($_SESSION["res"], $_REQUEST["sort"],$_REQUEST["dir"]);

    ?>

  • 8/3/2019 Php Procedimientos Al

    17/34

    Conrad Decker23-May-2006 03:56In regards to the previous post...you should actually be able to pipea mysql dump directly back into mysql.

    From the command line something likemysql -u username -p databasename < mysqldumpfilename

    should rebuild the database.

    There are some additional options one can use, and I believe mysqldumpfrom different versions of mysql may not be completely compatible.

    sb at stephenbrooks dot org01-May-2006 03:43I'm in the process of changing web hosts and my previous host provideda "dump" of the database in the form of a sequence of SQL requeststhat (I assume) have to be executed in order to rebuild the databaseon another system. It was generated using "MySQL dump 9.11". Queriesare finished by a semicolon and linefeed, while comment-lines beginwith a double hyphen. The script below opens a connection to an SQLserver and loads a dump file $file of this format into the database$dest_db.

    function load_db_dump($file,$sqlserver,$user,$pass,$dest_db){

    $sql=mysql_connect($sqlserver,$user,$pass);mysql_select_db($dest_db);$a=file($file);foreach ($a as $n => $l) if (substr($l,0,2)=='--') unset($a[$n]);$a=explode(";\n",implode("\n",$a));unset($a[count($a)-1]);foreach ($a as $q) if ($q)

    if (!mysql_query($q)) {echo "Fail on '$q'"; mysql_close($sql);return 0;}

    mysql_close($sql);

    return 1;}

    This may not be watertight if the ";\n" sequence appears insidequeries, but I hope it helps others who are in posession of suchdumps.

    caladorn at ugcs dot caltech dot edu19-Apr-2006 02:33After configuring php.ini as outlined above (set the extension_dirvariable and uncomment the appropriate mysql library) I kept receivingthe following error on every Apache restart:

    PHP Startup: Unable to load dynamic library './ext\\php_mysql.dll'

    After trawling the web, most suggestions seemed to center on copyingthe libmysql.dll from the php install directory toc:\windows\system32. While this can work, it can also complicatefuture upgrades, since you'll always have to copy the new libmysql.dllto insure proper operation.

    Instead, if you run a search for "libmysql.dll", you'll likely findseveral versions in various directories. After removing the older(smaller) versions from the other directories in my PATH, (c:\windows,c:\windows\system32) - and making sure the php install directory wasin the PATH, apache/php was able to successfully locate the correctDLL and start without errors.

    Hopefully someone will find this helpful. ;)Nathan Brizzee03-Apr-2006 12:42

    http://mx.php.net/manual/es/ref.mysql.php#66476http://mx.php.net/manual/es/ref.mysql.php#66476http://mx.php.net/manual/es/ref.mysql.php#66476http://mx.php.net/manual/es/ref.mysql.php#65478http://mx.php.net/manual/es/ref.mysql.php#65478http://mx.php.net/manual/es/ref.mysql.php#65478http://mx.php.net/manual/es/ref.mysql.php#64696http://mx.php.net/manual/es/ref.mysql.php#64696http://mx.php.net/manual/es/ref.mysql.php#64696http://mx.php.net/manual/es/ref.mysql.php#63912http://mx.php.net/manual/es/ref.mysql.php#63912http://mx.php.net/manual/es/ref.mysql.php#63912http://mx.php.net/manual/es/ref.mysql.php#63912http://mx.php.net/manual/es/ref.mysql.php#64696http://mx.php.net/manual/es/ref.mysql.php#65478http://mx.php.net/manual/es/ref.mysql.php#66476
  • 8/3/2019 Php Procedimientos Al

    18/34

    Hi,For all those who may still be struggling to get PHP to work withWindows and IIS, I finally found something that works.

    If you are getting the error message that function mysql_connect couldnot be found and you're sure you enabled php_mysql in php.ini this is

    what finally solved my problem.

    The post from mmw_canada at yahoo dot com on 10-Jul-2005 06:15 pointedme in the right direction. Thanks mmw_canada!

    1.) If you are connected to your Windows box via Remote Desktop, thereis a switch to Remote Desktop that will connect you to the consolesession. This is important because when IIS starts up, it's errormessages go to the console. If you are sitting at the physicalmachine, you can ignore this step.

    Here is the commandmstsc -v:10.192.186.xxx /F -console

    For a more complete list of supported commands, type this at a doscommand window:mstsc /?

    2.) Add a registry entry that tells PHP where to find its php.inifile. Copy the following text and paste it in a text file. Renamethe text file to something like phpini.reg and double-click it to addit to your registry.

    Windows Registry Editor Version 5.00

    [HKEY_LOCAL_MACHINE\\SOFTWARE\\PHP]"IniFilePath"="C:\\\\PHP"

    2.) Add c:\\php; (or wherever you unzipped PHP to) to your environmentvariable "Path". Here is the important part that caused me hours andhours of grief. When adding c:\\php; to the PATH environmentvariable, make SURE you add it BEFORE the path to CVSNT or MYSQL.PHP, CVSNT, and MYSQL all have a file called libmysql.dll. Searchorder is important for PHP to find its file libmysql.dll first. PHPmust come first in the search path. Otherwise you will get an errorfrom the DLL on the console screen when IIS starts up saying it can'tfind the specified function call.

    To see the order of your environment variables, open up a dos windowand type "set" and press enter. Look at what Path is equal to.

    c:\\php; better come before cvsnt and mysql or it will never workproperly.

    Hope this helps!

    brjann at gmail dot com01-Apr-2006 03:11After tearing my eyes out in frustration, I've finally found a way toenable extensions that always works for me. It's prettystraightforward.

    1. Download the latest zip-version of PHP.2. Delete (or backup) the contents of your PHP folder (usuallyc:\php). (remember to save any ext's not included in the zip)3. Copy everything in the zip-file into your PHP folder4. Be sure that extension_dir is set to "./ext" in php.ini5. Enable whichever extensions you want to use in php.ini

    http://mx.php.net/manual/es/ref.mysql.php#63834http://mx.php.net/manual/es/ref.mysql.php#63834http://mx.php.net/manual/es/ref.mysql.php#63834http://mx.php.net/manual/es/ref.mysql.php#63834
  • 8/3/2019 Php Procedimientos Al

    19/34

    I guess that deleting everything is quite unnecessary, the importantthing is that the php.exe and extensions in the same zip are ofcompatible versions. I've never found any need to change the PATHenvironment variable.

    Hope it helps!yp15-Mar-2006 04:08when using Fedora Core linux Mysql rpm installation.Configure as following to load the mysql header files../configure --with-mysql=/usr/Remember to do make clean to remove old configurations before compile

    php comments of fuzzyworm co., uk17-Feb-2006 05:13If you want to get PHP working nicely with MySQL, even with Apache,under Windows based systems, try XAMPP, from Apache Friends. It savesmessing about with config files, which is the only major problem withtrying to get the three to work together under windows.

    http://www.apachefriends.org/en/xampp-windows.html

    sabin at sabin dot com dot np14-Feb-2006 06:29php_mysql.dll and libmysql.dll for windows systems can be downloadedfromhttp://dev.mysql.com/downloads/connector/php/

    It can be useful to those who are using the PHP Windows installer,which does not have any external extensions included.

    elliotthird at tiscali dot co dot uk03-Feb-2006 11:20Oops! Don't use that one, use this:

    jeremy hepler20-Dec-2005 02:12For those of you on an OS that has older mysql libs and want toproperly authenticate to the modern mysql versions, without theOLD_PASSWORD hack; compile php with where you have installed thelatest mysql binary package:

    ./configure --with-mysql=/usr/local/mysql

    http://mx.php.net/manual/es/ref.mysql.php#63197http://mx.php.net/manual/es/ref.mysql.php#63197http://mx.php.net/manual/es/ref.mysql.php#63197http://mx.php.net/manual/es/ref.mysql.php#62013http://mx.php.net/manual/es/ref.mysql.php#62013http://mx.php.net/manual/es/ref.mysql.php#62013http://www.apachefriends.org/en/xampp-windows.htmlhttp://mx.php.net/manual/es/ref.mysql.php#61874http://mx.php.net/manual/es/ref.mysql.php#61874http://mx.php.net/manual/es/ref.mysql.php#61874http://dev.mysql.com/downloads/connector/php/http://dev.mysql.com/downloads/connector/php/http://mx.php.net/manual/es/ref.mysql.php#61451http://mx.php.net/manual/es/ref.mysql.php#61451http://mx.php.net/manual/es/ref.mysql.php#61451http://mx.php.net/manual/es/ref.mysql.php#59942http://mx.php.net/manual/es/ref.mysql.php#59942http://mx.php.net/manual/es/ref.mysql.php#59942http://mx.php.net/manual/es/ref.mysql.php#59942http://mx.php.net/manual/es/ref.mysql.php#61451http://dev.mysql.com/downloads/connector/php/http://mx.php.net/manual/es/ref.mysql.php#61874http://www.apachefriends.org/en/xampp-windows.htmlhttp://mx.php.net/manual/es/ref.mysql.php#62013http://mx.php.net/manual/es/ref.mysql.php#63197
  • 8/3/2019 Php Procedimientos Al

    20/34

    if you have mysql installed on seperate server, just drop it into thetarget directory on what ever machine you are compiling it on.

    Be sure to "make clean" before building or it may look in the previousplace.

    Use the output of mysql_get_client_info(); to test before and after.Joe Greklek15-Dec-2005 03:15I've seen alot of newbies getting frustrated over the extenstions notbeing installed initially, so heres a quick tut for Windows.

    It's ok to use the php5 installer. Just be sure to also grab the .zipor "manual" version of php5.

    Install it like any other app. It's pretty straight forward. Don'tforget to set the securities mentioned in the last message box at theend of the install. Next, If you installed php to c:\php then you willneed to add this to your PATH environment variable. This is a veryimportant step.

    Now open up the .zip manual version of php5 and extract the extfolder, and "libmysql.dll" to "c:\php\".

    You *MUST* set your security permissions on libmysql.dll and the extfolder to READ/READ&EXECUTE for IUSR_"MACHINE_NAME". like my machineis called master. If you don't do this you willrecieve an ******.dll - Access Denied. type message.

    Next edit your php.ini file usually located in c:\windows\.Find the line for extension_dir variable and make it sayextension_dir = "c:\php\ext\"

    Then scroll down a little bit and find the lines that say;extension=php_mbstring.dll;extension=php_bz2.dll;extension=php_curl.dll;extension=php_dba.dll;extension=php_dbase.dll;extension=php_exif.dll;extension=php_fdf.dll;extension=php_filepro.dll;extension=php_gd2.dll;extension=php_gettext.dll;extension=php_ifx.dll

    just remove the semicolin for each extension you would like loaded.Such asextention=php_mysql.dlland so on.

    Now just reboot and all should be well. Query away. you basically onlyneed to reboot to update the PATH environment variable. Hope thishelps at least 1 person.:)

    phil at pelanne dot com03-Nov-2005 09:46If you are experiencing extremely slow connections to MySQL from PHPfrom a Windows 2003 Server it may well not be PHP or IIS - try loadingmysql in in 'skip-name-resolve'-Mode.

    It may mean the difference between a 10 second load time and a splitsecond load time.

    Jonathon Hibbard21-Sep-2005 12:47

    http://mx.php.net/manual/es/ref.mysql.php#59793http://mx.php.net/manual/es/ref.mysql.php#59793http://mx.php.net/manual/es/ref.mysql.php#59793http://mx.php.net/manual/es/ref.mysql.php#58415http://mx.php.net/manual/es/ref.mysql.php#58415http://mx.php.net/manual/es/ref.mysql.php#58415http://mx.php.net/manual/es/ref.mysql.php#57013http://mx.php.net/manual/es/ref.mysql.php#57013http://mx.php.net/manual/es/ref.mysql.php#57013http://mx.php.net/manual/es/ref.mysql.php#57013http://mx.php.net/manual/es/ref.mysql.php#58415http://mx.php.net/manual/es/ref.mysql.php#59793
  • 8/3/2019 Php Procedimientos Al

    21/34

    This is a small function I wrote to handle queries on a table.It can query a table, order and sort, and supports inner joins.

    This function also returns the result as a single row or all rows.

    Enjoy :

  • 8/3/2019 Php Procedimientos Al

    22/34

    Variable type is : ".gettype($where));}!empty($group_by) ? $sql .= " GROUP BY ".$group_by : '';!empty($order_by) ? $sql .= " ORDER BY ".$order_by : '';!empty($asc) ? $sql .= " ".$asc : '';$sql .= " # Query resides in ".__FILE__."->".$C_NAME."

    on line ".__LINE__;if($return_array === true) {$rst = mysql_query($sql)

    or die("An Error Has Occurred!\n MySQL Error Reports : ".mysql_error()."\n The Error Occured in ".__FILE__." -> ".$C_NAME);

    $i=0;while($row = mysql_fetch_assoc($rst)) {

    $rowRst[] = $row[$fields[$i]];$i++;

    }} else {

    $rst = mysql_query($sql)or die("An Error Has Occurred!

    \n MySQL Error Reports : ".mysql_error()."\n The Error Occured in ".__FILE__." -> ".$C_NAME);

    $rowRst = mysql_fetch_assoc($rst);}return $rowRst;

    }?>

    nick smith19-Sep-2005 02:07i'm fairly new to this but have just managed to set up (on windows xp)apache 2.0.54 with php 5.0.4 and mySQL 4.1.13, also phpMyAdmin 2.6.4having had exactly the problems reported by so many others. i wasntactually aware of mySQL not being loaded in php until i tried to use

    phpmyadmin and it told me to check my php/mysql configuration.

    basically i just did everything that is mentioned by others (settingextension_dir to c:\php\ext ( not c:\php\ext\ ), uncommentingextension=php_mysql.dll from php.ini and putting c:\php into my PATH)but i was still getting the infuriating message when trying to startapache that php_mysql.dll could not be found.

    i restarted my machine and it worked! It seems i had to restartwindows after editing my PATH. i didnt bother restarting until it wasthe last resort because on xp i have NEVER had to do this before -changes to System Variables always took effect immediately. I couldunderstand this on, say, windows 98 where you put the addition to yourPATH into your autoexec.bat but why i had to do this with xp is amystery.

    Anyway, give it a go, it might save you tearing out prescious hair!

    N.

    avis_del at yahoo dot com01-Sep-2005 03:14I aggree with j at jonathany.com

    PHP 5.04 to MySQL,php_mysql.dll will not found on windows installer (.msi)just extract from .zip file (can download).It works.

    1. cgi.force_redirect = 02. extension_dir = "c:\php\ext"

    http://mx.php.net/manual/es/ref.mysql.php#56927http://mx.php.net/manual/es/ref.mysql.php#56927http://mx.php.net/manual/es/ref.mysql.php#56927http://mx.php.net/manual/es/ref.mysql.php#56389http://mx.php.net/manual/es/ref.mysql.php#56389http://mx.php.net/manual/es/ref.mysql.php#56389http://mx.php.net/manual/es/ref.mysql.php#56389http://mx.php.net/manual/es/ref.mysql.php#56927
  • 8/3/2019 Php Procedimientos Al

    23/34

    3. extension=php_mysql.dll

    untill on phpinfo.php show

    MySQL Support enabledActive Persistent Links 0

    Active Links 0Client API version 4.1.12

    claude(at)claude(dot)nl25-Aug-2005 09:23A note on resources

    When a resource (e.g. a link identifier) runs out of scope, it isdeleted and the associated computer resources (e.g. the tcp link tothe database) will be terminated as well. So far so good!However, in the following code the tcp mysql link persists until theend of execution:This is because the internally the link-identifier is being saved, sothat subsequent mysql functions will work. There seems to be no way todelete this internal reference.If you were, however, to open 2 connections, the oldest one will bedeleted automatically (so the connection to hostname will terminate atthe $conn=null statement, the connection to hostname2 will exist tillthe end of the script).

    arjen at mysql dot com04-Aug-2005 03:26John Coggeshall wrote a PHP5 ext/mysqli compatibility script forapplications that still use the old ext/mysql functions. This preventsthe hassle of trying to have both the mysql and mysqli extensionsloaded in PHP5, which can be tricky.

    The script is at:http://www.coggeshall.org/oss/mysql2i/

    allan666 at NOSPAM dot gmail dot com20-Jul-2005 05:37[Editor's Note: In MySQL v5.0+, you can use the INFORMATION_SCHEMA

    tables to retrieve information on tables, views, databases and so [email protected]]

    Here is a small function to parse a mysql creation table DDL. Thefunction takes a string with the SQL code to create a table andreturns the table name, table fields, table key fields and fieldstype, all in arrays (except by the name, obviously). The functionrequires that the primary key be named "id" and the foreign keys named"id...". All foreign key types are suposed to be int (or itsvariations, bigint, etc...). All those restrictions are easilymodified to others needs.

    Here is a example of a DDL code.

    CREATE TABLE `telefones` (`id` int(11) NOT NULL auto_increment,

    http://mx.php.net/manual/es/ref.mysql.php#56166http://mx.php.net/manual/es/ref.mysql.php#56166http://mx.php.net/manual/es/ref.mysql.php#56166http://mx.php.net/manual/es/ref.mysql.php#55489http://mx.php.net/manual/es/ref.mysql.php#55489http://mx.php.net/manual/es/ref.mysql.php#55489http://www.coggeshall.org/oss/mysql2i/http://mx.php.net/manual/es/ref.mysql.php#54941http://mx.php.net/manual/es/ref.mysql.php#54941http://mx.php.net/manual/es/ref.mysql.php#54941http://mx.php.net/manual/es/ref.mysql.php#54941http://www.coggeshall.org/oss/mysql2i/http://mx.php.net/manual/es/ref.mysql.php#55489http://mx.php.net/manual/es/ref.mysql.php#56166
  • 8/3/2019 Php Procedimientos Al

    24/34

    `id_tipo_telefone` int(11) NOT NULL default '0',`numero` varchar(15) NOT NULL default '',`id_pessoa` int(11) NOT NULL default '0',PRIMARY KEY (`id`),KEY `id_tipo_telefone` (`id_tipo_telefone`),KEY `id_pessoa` (`id_pessoa`),

    CONSTRAINT `0_775` FOREIGN KEY (`id_tipo_telefone`) REFERENCES`tipos_telefone` (`id`),CONSTRAINT `0_776` FOREIGN KEY (`id_pessoa`) REFERENCES `pessoas`

    (`id`)) TYPE=InnoDB

    that returns

    $tbname = "telefones"$fields = array("numero");$kfields = array("id_tipo_telefone","id_pessoa");$tipos = array("varchar");

    Hope it helps...

  • 8/3/2019 Php Procedimientos Al

    25/34

    mmw_canada at yahoo dot com10-Jul-2005 08:15I Quote:

    "Note: If when starting the web server an error similar to thefollowing occurs: "Unable to load dynamic library './php_mysql.dll'",this is because php_mysql.dll and/or libmysql.dll cannot be found by

    the system."

    Actully, the file may have been found, it is just the wrong version.

    The "libmysql.dll" is packaged and sent with a number of applicationsand it can end up in different place on your computer. The file mayeven be completely different, so just replacing it may cause problemswith the other applications.

    I searched for the this file and found that I had a number ofdifferent versions on my machine at once. PHP was trying to use theWRONG ONE.

    Maybe the name should be changed in later versions so that it doesn'tencourage people to commit suicide or pull their hair out.

    bahatest at ifrance dot com07-Jul-2005 12:38/** before mysql 4.1, timestamp have a defined size, but after 4.1,timestamp is equal to... datetime* so, conversion is automatic when you import your dump in new mysqlversion, but your script cannot echo dates like before.* this function took one date on DATETIME format, a size of oldtimestamp format and return the date in old timestamp format before4.1* Note : if $date is in TIMESTAMP format, the function return itunaltered. So we can patch our php code before migrate to 4.1

    * @param $date a date in DATETIME format, or TIMESTAMP format aftermysql 4.1* @param $size a size of old TIMESTAMP format (14,12,10,8,6,4 or 2)* @return the date in old TIMESTAMP format*/function mysql_convert_timestamp_to_previous_usage($date, $size) {

    $tab=split('[- :]', $date);if (sizeof($tab) != 6) return $date;if (($size!= 8) && ($size!= 14)) {

    $tab[0]=substr($tab[0], -2);}for ($i = 12; $i>$size; $i-=2) {

    unset($tab[sizeof($tab)-1]);

    }if ($size== 8) unset($tab[sizeof($tab)-1]);return implode("", $tab);

    }

    jimmy dot a dot gunawan at gmail dot com03-Jul-2005 02:18I almost desperately connect my apache 2.0.54 winversion to PHP 5.0.4and MYSQL 4.1.12 under windows, since there are lack of any accurateinformation to setup them properly.If you got any error message said: "Call to undefined functionmysql_connect()", here is the right tips.

    Apache installed in c:\apache\apachegroupPHP installed in c:\php

    Mysql installed in c:\mysql

    1. Find and add c:\apache\apachegroup\conf\httpd.conf

    http://mx.php.net/manual/es/ref.mysql.php#54637http://mx.php.net/manual/es/ref.mysql.php#54637http://mx.php.net/manual/es/ref.mysql.php#54637http://mx.php.net/manual/es/ref.mysql.php#54528http://mx.php.net/manual/es/ref.mysql.php#54528http://mx.php.net/manual/es/ref.mysql.php#54528http://mx.php.net/manual/es/ref.mysql.php#54414http://mx.php.net/manual/es/ref.mysql.php#54414http://mx.php.net/manual/es/ref.mysql.php#54414http://mx.php.net/manual/es/ref.mysql.php#54414http://mx.php.net/manual/es/ref.mysql.php#54528http://mx.php.net/manual/es/ref.mysql.php#54637
  • 8/3/2019 Php Procedimientos Al

    26/34

    with:ScriptAlias /php/ "c:/php/"AddType application/x-httpd-php .phpAction application/x-httpd-php "/php/php-cgi.exe"

    2. Go to php directory c:\php then rename php.ini-dist to php.ini(or make a new php.ini based on old php.ini file),

    make sure we set the right extension:extension_dir = "c:\php\ext"extension=php_mysql.dll

    If you setup an php script that call function php_info();and you can find table:MySQL Support enabledActive Persistent Links 0Active Links 0Client API version 4.1.7

    that mean the mysql.dll properly attached to suppport the php, happySQL-ing

    Microsoul V304-Jun-2005 05:47I use IIS 6, PHP 5.04, Windows Server 2003 and MySQL 4.1.11. and hereis what I was able to figure out.To get MySQL and PHP to talk to each other, in the php.cfg, dontforget to turn on the tagcgi.force_redirect = 0, and make sure you set it at 0 (it is defaultat 1. just delete the semi-colon from in front of it to activate it inthe code) Then the phpinfo will say its reading the cfg from your PHPinstall directory instead of your WINDOWS root. Then your phpinfo willshow the MySQL entry that some people may be having a hard time with.No registry settings or copying of anything is needed. Also follow therest of the excellent help from the user comments. Here's what I did,to make it simple:

    I made a folder in the folder tree just above program files (exploreyour computer) and named it PHP. I extracted the .zip php version intoit (not the auto install version). I edited the php.ini-recommended,renamed it to just php, added my sql username, database name, etc.(you really gotta look closely at the cfg file and make sure you dontoverlook something). Turned on the extension=php_mysql.dll (justdelete the semi-colon thats in front of it). Added the php folder tothe PATH (instructions on how to do this are pretty simple, anddocumented above). I also made the ext folder available to the PATH,but Im not sure if it's really necessary. The user comments are whatreally helped me, so I thought I would return the favor, and try toexpand on this topic a little bit.

    noel at nettensity dot com29-May-2005 01:20

    More On Windows 2003 Server / IIS 6.0:

    It might (probably) be necessary to add both the path to PHP and thepath to the extensions dir to your environmental variables.

    To do this:1) Right-Click on 'My Computer'2) Select 'Properties'3) Click the 'Advanced' tab4) At the bottom of this dialog box, click the 'EnvironmentalVariables' button5) In the frame titled 'System Variables', scroll-down until you find'Path'

    6)Add your path to PHP and your path to the extensions folder i.e.c:\php;c:\php\ext. Make sure all the paths are seperated by semi-colons, and make sure not to erase any of the other paths already in

    http://mx.php.net/manual/es/ref.mysql.php#53527http://mx.php.net/manual/es/ref.mysql.php#53527http://mx.php.net/manual/es/ref.mysql.php#53527http://mx.php.net/manual/es/ref.mysql.php#53330http://mx.php.net/manual/es/ref.mysql.php#53330http://mx.php.net/manual/es/ref.mysql.php#53330http://mx.php.net/manual/es/ref.mysql.php#53330http://mx.php.net/manual/es/ref.mysql.php#53527
  • 8/3/2019 Php Procedimientos Al

    27/34

    there.

    I meant to include this in my note below, apologies for any confusion.

    noel at nettensity dot com29-May-2005 12:04Enabling MySQL with Windows Server 2003/IIS 6.0:Find your php.ini file first, check phpinfo() to see where php is

    currently looking for php.ini. (i.e. Using the Windows installer forPHP 5.0.4, the php.ini file was placed in the C:\Windows dir.) Irecommend, however, that you don't use the installer - go with fullmanual install.

    Set the following in php.ini:display_errors = onerror_reporting = E_ALLThis will make sure that you'll see any errors that arise duringconfiguration. MAKE SURE TO CORRECT THESE WHEN YOU ARE DONE PLAYINGWITH PHP.INI! Do not leave these settings like this on a productionmachine.

    In php.ini set the following:extension_dir = "pathtoextensions (ususally [yourpathtophp]\ext)"extension=php_mysql.dll (make sure this is un-commented if its alreadyin your php.ini)

    In IIS, open Web Service Extensions, click "Add a new Web serviceextension..."Type-in PHP for the extension nameUnder required files:Add [yourpathtophp]\php5isapi.dllAdd [yourpathtophp]\php5ts.dllClick 'Apply' then click 'OK'

    Create web sites like you normally would, but make sure they haveexecutable permissions, not just script access. Under the "HomeDirectory" tab, click 'Configuration'. Scroll down the list at the topand see if you can find PHP. If you do, make sure the path to theexecutable for PHP is correct. If you don't find PHP in the list,click 'Add...', then browse to the correct executable,[yourpathtophp]\php5isapi.dll, and click OK. In the extension field,enter 'PHP'. Verbs should already be set to 'All verbs', leave it likethat.

    Create a test page with this code:call it test.php, and place this file into the web site you justcreated. Browse to the page, with firefox preferably ;), and make surethat you have a MySql section with some MySql info in there. If not,then your paths are possibly screwed up, or you're still not editingthe correct php.ini (again, look at the location that phpinfo() showsyou, and just edit it there if you have to, then move it afterwardsand re-config).

    Hope this helps!

    disappear dot nz at gmail dot com21-May-2005 11:39Hi,

    this is a small OOP script to provide an easy connction to the mysqldb and to get associative / logical / both arrays.

  • 8/3/2019 Php Procedimientos Al

    28/34

    class mysql_array{

    public function __construct ( $s_host , $s_user , $s_pass ,$s_db )

    {

    $this -> r_conn = mysql_connect ( $s_host , $s_user ,$s_pass ) or die ( mysql_error ( ) ) ;mysql_select_db ( $s_db ) ;

    }

    private function array_make ( $s_sql , $i_type ){

    $r_rs = mysql_query ( $s_sql , $this -> r_conn ) or die (mysql_error ( ) ) ;

    while ( $a_col = mysql_fetch_array ( $r_rs , $i_type ) ){

    $a_rs [ ] = $a_col ;}mysql_free_result ( $r_rs ) ;return ( $a_rs ) ;

    }

    public function array_logic ( $s_sql ){

    $a_rs = $this -> array_make ( $s_sql , MYSQL_NUM ) ;return ( $a_rs ) ;

    }

    public function array_assoc ( $s_sql ){

    $a_rs = $this -> array_make ( $s_sql , MYSQL_ASSOC ) ;return ( $a_rs ) ;

    }

    public function array_both ( $s_sql ){

    $a_rs = $this -> array_make ( $s_sql , MYSQL_BOTH ) ;return ( $a_rs ) ;

    }

    }

    $o_mysql = new mysql_array ( 'localhost' , 'user' , 'pass' , 'db') ;

    $s_sql = "SHOW TABLES" ;

    $a_rs = $o_mysql -> array_assoc ( $s_sql ) ;

    echo '' ;print_r ( $a_rs ) ;

    ?>

    medic at setiherbipolis dot de15-May-2005 10:42Client does not support authentication protocol requested by server;consider upgrading MySQL client

    means that you're using an old version of MySQL Client ( possibly notmysqli)

    Authentication protocol for MySQL has changed with version 4.1.

    http://mx.php.net/manual/es/ref.mysql.php#52858http://mx.php.net/manual/es/ref.mysql.php#52858http://mx.php.net/manual/es/ref.mysql.php#52858http://mx.php.net/manual/es/ref.mysql.php#52858
  • 8/3/2019 Php Procedimientos Al

    29/34

    To get a hint at which mysql-client version you're using tryphpinfo();

    06-Mar-2005 01:01If you are installing PHP5 on Windows 2003 server (AKA Win 2k3) andneed MySQL to work using the either the php_mysql.dll orphp_mysqli.dll or both of them at the same time, and MySQl isn't

    showing up in phpinfo, then your php.ini is probably not loading. Inthe direction in the PHP 5 zip file, they will tell you to add yourPHP install directory to your windows path. This should tell phpwhere to load its php.ini from but it doesn't. If you want to getthis to work, you don't have to copy any DLL's anywhere like everyonesuggests. All you have to do is add the folling regsitry key towindows:

    [HKEY_LOCAL_MACHINE\SOFTWARE\PHP]"IniFilePath"="C:\\PHP"

    simply copy the above 2 lines of code into a text file and save thefile as php_ini_path.reg

    After you save the file it will look like a registry file. Simplydouble click on it.

    It will make it so PHP will look for your php.ini in C:\PHP. I wouldassume you can edit this if you install php into a different location,but I haven't tried that.

    After running the reg file, make sure your php.ini is in your PHP dirand make sure all the appropriate things are set. This should get youup and running. Make sure you also follow all the steps on how tomake it work in IIS. This is just an addition to the direction.

    Protik Mukherjee03-Mar-2005 11:34

    Fedora mysql problems!!In Fedora 3 the php mysql module does not come with the defaultinstallation. To install it use $>yum install php_mysqlIf u dont do this you will get errors with mysql functions likemysql_connect()

    Hope this helps!

    tumaine no at spam verizon net23-Dec-2004 10:21I had a hard time with upgrading to php version 5.2.0 in Windows XPPro since mySQL queries all of a sudden stopped working and led toblank pages on my site. I spent a good half day searching googletrying to figure out this problem, and didn't quite know how compilingPHP would help me. It is not necessary. Set up PHP manually with the

    ZIP folder download.

    This is a good link to read and wish I found it earlier:

    http://www.zend.com/manual/install.windows.extensions.php

    If you are getting an error popup about not being able to load somemysql.dll when starting apache, you need to change this in yourphp.ini file:

    extension_dir = "./" to something like "c:\php\ext"

    Also what I was doing wrong was that I forgot to uncomment the

    following line in my php.ini file:

    extension=php_mysql.dll

    http://mx.php.net/manual/es/ref.mysql.php#50659http://mx.php.net/manual/es/ref.mysql.php#50659http://mx.php.net/manual/es/ref.mysql.php#50569http://mx.php.net/manual/es/ref.mysql.php#50569http://mx.php.net/manual/es/ref.mysql.php#50569http://mx.php.net/manual/es/ref.mysql.php#48434http://mx.php.net/manual/es/ref.mysql.php#48434http://mx.php.net/manual/es/ref.mysql.php#48434http://www.zend.com/manual/install.windows.extensions.phphttp://www.zend.com/manual/install.windows.extensions.phphttp://mx.php.net/manual/es/ref.mysql.php#48434http://mx.php.net/manual/es/ref.mysql.php#50569http://mx.php.net/manual/es/ref.mysql.php#50659
  • 8/3/2019 Php Procedimientos Al

    30/34

    Restart apache, and everything should work.

    Thought that I could save someone time and frustration when upgrading,since versions 5+ do not include mySQL support by default as earlierversions apparently do.

    jon at mysql dot com11-Dec-2004 04:32Re Pat's note: You can add the --old-passwords option in the [mysqld]section of your MySQL my.cnf or my.ini configuration file. This optionwill force the MySQL server to use the old-style password hashing forall connections. This is not really recommended, as it's less secure,but will allow you to use existing accounts without resetting thepasswords.

    Of course, as already mentioned, you can use the MySQL OLD_PASSWORD()function instead to handle this issue on an account-by-account basis.

    The optimal solution when migrating to MySQL 4.1+ from a previousversion is to upgrade to PHP 5 (if you're not using it already) and

    rewrite any code accessing MySQL using the mysqli extension, which ismore secure and provides a much better API.

    For more information, see the MySQL Manual:http://dev.mysql.com/doc/mysql/en/Application_password_use.html

    lkujala at uniserve dot com18-Nov-2004 03:43PROBLEM:Error Message: the specified module could not be found.When trying to load a php_mysql.dll / php_mysqli.dll / php_mssql.dllextension on a Windows platform.

    CAUSE:The standard windows installer package is rather incomplete; it does

    not include any of the DLL's needed for the optional extensions. Inorder to use any extension you need to install the FULL zipdistribution (unless you like fooling around with dll hell), not justthe php_*.dll extensions. You might as well include ALL of the DLL'ssince the dependencies as documented are wrong (i.e. you need morethan libmysql.dll for the php_mysql.dll to load).

    I did find the standard windows installer useful for the inital setupthough.

    nleippe at integr8ted dot com12-Oct-2004 05:22trace_mode breaks SQL_CALC_FOUND_ROWS.This is because it emits an EXPLAIN before sending the by itself, thus the subsequent SELECT FOUND_ROWS() is no longer the

    next consecutive query, and the result is zero.This was true for me for at least MySQL 4.0.21 and 4.1.5gamma.(PHP 4.3.9)

    Melvin Nava: e-4(at)venezolano.web.ve13-Sep-2004 02:02To count page hits, just put next code in a text file and include itin every one of your pages. It will log even different querystrings asdifferent pages. (a MySQL database and table is needed first)

    This can be a pretty good example of what you can do with PHP andMySQL. I made this script to log and show all hits in:http://www.venezolano.web.ve/

  • 8/3/2019 Php Procedimientos Al

    31/34

    CREATE TABLE `stats_pagecounter` (

    `id` int(25) NOT NULL auto_increment,`page_name` varchar(255) NOT NULL default '',`page_hits` int(25) NOT NULL default '0',PRIMARY KEY (`id`)

    ) TYPE=MyISAM;

    **************************COUNTING STARTS*************************/function page_count($page) {

    $c_link = mysql_connect('localhost', 'username','password')

    or die('counter CONNECT error: '.mysql_errno().','.mysql_error());

    mysql_select_db('database_name');$c_query = "SELECT * FROM stats_pagecounter

    WHERE (page_name = '$page')";$c_result = mysql_query($c_query, $c_link)

    or die('counter SELECT error: '.mysql_errno().','.mysql_error());

    if (mysql_num_rows($c_result)) {$row=mysql_fetch_array($c_result,MYSQL_ASSOC);$pcounter = $row['page_hits']+1;$c_update = "UPDATE stats_pagecounter

    SET page_hits = '$pcounter' WHERE page_name = '$page'";$c_hit = mysql_query($c_update, $c_link)

    or die('counter UPDATE error: '.mysql_errno().','.mysql_error());

    } else {$c_insert = "INSERT INTO stats_pagecounter

    VALUES ( '0', '$page', '1')";$c_page = mysql_query($c_insert, $c_link)

    or die('counter INSERT error: '.mysql_errno().','.mysql_error());

    $pcounter = 1;}mysql_free_result($c_result);mysql_close($c_link);return $pcounter;

    }$phpself_url = $_SERVER['SERVER_NAME'].

    $_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'];

    $page_hits = page_count($phpself_url);

    /************************COUNTING ENDS*************************/

    /************************Put next line in a page to show his page hits(If you want to)************************/echo $page_hits;?>

    aidan at php dot net15-Aug-2004 07:59If you want to replicate the output of `mysql --html`, printing yourresults in a HTML table, see this function:

    http://aidanlister.com/repos/v/function.mysql_draw_table.php

    http://mx.php.net/manual/es/ref.mysql.php#44750http://mx.php.net/manual/es/ref.mysql.php#44750http://mx.php.net/manual/es/ref.mysql.php#44750http://aidanlister.com/repos/v/function.mysql_draw_table.phphttp://aidanlister.com/repos/v/function.mysql_draw_table.phphttp://mx.php.net/manual/es/ref.mysql.php#44750
  • 8/3/2019 Php Procedimientos Al

    32/34

    irn-bru at gmx dot de27-May-2004 07:27Note, that the sql.safe_mode configuration setting does effect allmysql_* functions. This has nothing to to with the php safe mode,check the [SQL] section in php.ini.

    I found out, that if you set sql.safe_mode = On, mysql_connect will

    ignore provided username and passwort and makes use of the scriptowner instead (checked on debian).

    Brian

    Pat22-Jan-2004 05:02[Editor Note:The password hashing was updated in MySQL 4.1, you must use the MySQLiextension with MySQL 4.1+ (or use the following method to allowpre 4.1 clients to connect).]

    MySQL 5.0 has a new password system, and PHP cannot connect to itbecause it cannot send a correct password. You must use the MySQLcommand OLD_PASSWORD() when adding a user to the database, or PHP

    cannot connect as of the library that comes with PHP 5.0Beta3gyohng at netscape dot net20-Jun-2003 12:16The following page contains a complete easy to read tutorial of MySQLprogramming with PHP.

    http://www.yohng.com/phpm/

    soren at byu dot edu14-Mar-2003 03:23Let's say that you want to generate a MySQL password hash from a plaintext password. Normally, you would just submit the MySQL query"SELECT PASSWORD('password')", but if for some reason you can't accessto MySQL database directly, then you can use the following function(translated right out of the MySQL source code):

    example:

    outputs:

    http://mx.php.net/manual/es/ref.mysql.php#42726http://mx.php.net/manual/es/ref.mysql.php#42726http://mx.php.net/manual/es/ref.mysql.php#42726http://mx.php.net/manual/es/ref.mysql.php#39276http://mx.php.net/manual/es/ref.mysql.php#39276http://mx.php.net/manual/es/ref.mysql.php#39276http://mx.php.net/manual/es/ref.mysql.php#33271http://mx.php.net/manual/es/ref.mysql.php#33271http://mx.php.net/manual/es/ref.mysql.php#33271http://www.yohng.com/phpm/http://mx.php.net/manual/es/ref.mysql.php#30347http://mx.php.net/manual/es/ref.mysql.php#30347http://mx.php.net/manual/es/ref.mysql.php#30347http://mx.php.net/manual/es/ref.mysql.php#30347http://www.yohng.com/phpm/http://mx.php.net/manual/es/ref.mysql.php#33271http://mx.php.net/manual/es/ref.mysql.php#39276http://mx.php.net/manual/es/ref.mysql.php#42726
  • 8/3/2019 Php Procedimientos Al

    33/34

    70de51425df9d787

    Which is the same result you get if you do "SELECT PASSWORD('hello')"directly in MySQL. Hopefully you'll never be in a situation where youhave to use this, but if you need it (like I did), it's here.

    past at sbox dot tugraz dot at21-Feb-2003 04:17

    As MySQL docs say, RAND() is not very usefull for generation ofrandomized result orders.

    But this worked for me on Linux, however:Somewhere before:mt_srand((double)microtime()*1000000);

    "SELECT *, " RAND(".mt_rand(0,86622340).")*10000%100 AS randomvalueORDER BY randomvalue"

    The upper value for mt_rand() has to be Quite Big to see any effect onMySQL's RAND(). The exact number shouldn't be significant. Note themultiplication and modulo; MySQL seems to count steadily upwards when

    generating random numbers, so we take some numbers from between.mijnpc at xs4all dot nl20-Nov-2002 04:33If you have a Windows machine running a webserver with PHP you don'tneed to install MySQL server to locally test scripts, if you aregranted to establish a Secure Telnet connection (port 22) to theremote webserver.

    To do this you need a Secure Telnet client, which supports port-forwarding.Before you establish a connection, define the port-forward.Forward local port 3306 to [name or ip of remote server]:3306Make sure that local ports accept connections from other hostsSave this session

    Connect to remote server with username and passwordMinimize the shell and that's it...

    You can use the same username (and password) as if you were working onthe remote server !E.g. : $link = mysql_connect("localhost", "root", "") or die("no wayjose");

    You may get a shell-timeout after xx minutes depending on your remoteserver, just reconnect or press enter in the shell once in a while...

    An example of a superb freeware Secure Telnet client is Putty : Putty

    :http://www.chiark.greenend.org.uk/~sgtatham/putty/

    This 'discovery' really has saved me a lot of time because I don'thave to upload the scripts to the remote server time and time again,pressing [save] is enough, heh (-:

    jeyoung at priscimon dot com25-Apr-2002 11:23[Ed. Note:This may be due to the fact that subsequent calls to mysql_connectwith the same parameters return the same resource id for theconnection, so in reality it is using the same connection. In orderto force a new link, you must specify the new_link parameter inmysql_connect.]

    MySQL transactions

    MySQL supports transactions on tables that are of type InnoDB. I have

    http://mx.php.net/manual/es/ref.mysql.php#29692http://mx.php.net/manual/es/ref.mysql.php#29692http://mx.php.net/manual/es/ref.mysql.php#29692http://mx.php.net/manual/es/ref.mysql.php#27029http://mx.php.net/manual/es/ref.mysql.php#27029http://mx.php.net/manual/es/ref.mysql.php#27029http://www.chiark.greenend.org.uk/~sgtatham/putty/http://www.chiark.greenend.org.uk/~sgtatham/putty/http://mx.php.net/manual/es/ref.mysql.php#21019http://mx.php.net/manual/es/ref.mysql.php#21019http://mx.php.net/manual/es/ref.mysql.php#21019http://mx.php.net/manual/es/ref.mysql.php#21019http://www.chiark.greenend.org.uk/~sgtatham/putty/http://mx.php.net/manual/es/ref.mysql.php#27029http://mx.php.net/manual/es/ref.mysql.php#29692
  • 8/3/2019 Php Procedimientos Al

    34/34

    noticed a behaviour which is puzzling me when using transactions.

    If I establish two connections within the same PHP page, start atransaction in the first connection and execute an INSERT query in thesecond one, and rollback the transaction in the first connection, theINSERT query in the second connection is also rolled-back.

    I am assuming that a MySQL transaction is not bound by the connectionwithin which it is set up, but rather by the PHP process that sets itup.

    This is a very useful "mis-feature" (bug?) because it allows you tocreate something like this:

    class Transaction {var $dbh;

    function Transaction($host, $username, $password) {$this->dbh = mysql_connect($host, $username, $password);

    }

    function _Transaction() {mysql_disconnect($this->dbh);

    }

    function begin() {mysql_query("BEGIN", $this->dbh);

    }

    function rollback() {mysql_query("ROLLBACK", $this->dbh);

    }

    function commit() {mysql_query("COMMIT", $this->dbh);

    }}

    which you could use to wrap around transactional statements like this:

    $tx =& new Transaction("localhost", "username", "password");$tx->begin();$dbh = mysql_connect("localhost", "username", "password");$result = mysql_query("INSERT ...");if (!$result) {

    $tx->rollback();

    } else {$tx->commit();

    }mysql_disconnect($dbh);unset($tx);

    The benefit of such a Transaction class is that it is generic and canwrap around any of your MySQL statements.

    nospam at nospam dot nos19-Nov-2001 11:17ever wanted to know the date a table was last updated? use this:

    $info = mysql_fetch_array(mysql_query("show table status fromdatabasename like 'tablename'"));echo $info["Update_time"];

    http://mx.php.net/manual/es/ref.mysql.php#16925http://mx.php.net/manual/es/ref.mysql.php#16925http://mx.php.net/manual/es/ref.mysql.php#16925http://mx.php.net/manual/es/ref.mysql.php#16925