網頁

顯示具有 MySQL 標籤的文章。 顯示所有文章
顯示具有 MySQL 標籤的文章。 顯示所有文章

2013年12月13日 星期五

MySQL Ajax Table Editor

php/AjaxTableEditor.php function doQuery($query) mysql_query("SET NAMES 'UTF8'"); //解決 PHP/mySQL 資料庫讀取中文顯示亂碼或問號

2013年11月21日 星期四

Wordpress and MySQL

UPDATE
 

        $option_tree_value_mysql = 's:5:"title";s:9:"post";s:4:"page";';
        $table_name = 'wp_options';
        $option_id =100;
        $sql = "UPDATE $table_name SET option_value='$option_tree_value_mysql'  WHERE option_id=$option_id";
  $ereminders = $wpdb->query($wpdb->prepare($sql));


 

    /* 參數測試 */
    $wp_user_id =2;
    $wp_post_id =1;

 
    $user_blogs_array =  get_blogs_of_user( $wp_user_id ); //Notice: 開啓debug模式有 wordpress 3.1前棄用的訊息

 foreach ($user_blogs_array AS $user_blog) {

      $wp_blog_id = $user_blog->userblog_id;
     
 }
     $table_name = 'wp_'.$wp_blog_id.'_postmeta';//'wp_2_options';
     $sql = "UPDATE $table_name SET meta_value=%d  WHERE meta_key='條件' AND post_id='1'";
  $ereminders = $wpdb->query($wpdb->prepare($sql,3)); 


2013年11月6日 星期三

php mysql utf8

 000webhost的資料庫編碼修正(utf-8)

 

            $sql="INSERT INTO ".  db('tablename') . " (area_id,name,address, lat, lng) VALUES('$city','$name','$address','$lat','$lng')";
       

          $db_link = mysql_connect(db('hostname'),db('username'),db('password')); 
           mysql_select_db(db('dbname'), $db_link); 
           mysql_query("SET NAMES 'utf8'", $db_link); 
           //$sql="INSERT INTO cafe_map SET name='".$name."'";
           mysql_query($sql, $db_link); 

          echo mysql_error($db_link); 
    

             $con=mysqli_connect(db('hostname'),db('username'),db('password'),db('dbname'));
            // Check connection
            if (mysqli_connect_errno())
              {
              echo "Failed to connect to MySQL: " . mysqli_connect_error();
              }

             $con->query("SET NAMES 'utf8'");
            $result = mysqli_query($con,"SELECT * FROM  ".db('tablename'));
       



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

                  $LatLng =  "(".$row['lat'].",".$row['lng'].")";  
                  $item_id =$row['id']; 
                  $ScenicName  =$row['name']; 
                  $phpecho = $phpecho.$row['id'].$LatLng; 

                  $locations_db_json.='{';
                  $locations_db_json.= 'latlng : new google.maps.LatLng';
                  $locations_db_json.= $LatLng;//'(25.0336148,120.56480220000003)';
                  $locations_db_json.=',';  
                  $locations_db_json.= 'info :';  
                  $locations_db_json.= '"'.$row['id'].":".$ScenicName.'"'; ;//'"hello"';  $markerName
                  $locations_db_json.= '},';
            
              }

            mysqli_close($con);
  

2013年9月26日 星期四

jQuery load php MySQL

index.php
 






Your Message is loading..

data.js
 

  var  server_url = location.href.replace(location.pathname, ""); //http://localhost
 // alert(server_url);
  var msg;  var url_php;
  var auto_refresh = setInterval(
  
 function ()
 {

   //http://localhost/php/chat/db/chat_db.php  
          url_php =  server_url+"/php/chat/db/chat_db.php";
  
    
     var msg = input; //from index.php
     var getData =  'msg='+ msg ;     
    
        $.ajax({
             url: url_php,
             datatype: "json",
             data: getData,
             type: 'get',
              success: function (response) {   
                
             var message= response["message"];
                   // alert(message);
                   // console.log(message);
                     document.getElementById('msg_id').innerHTML = message;
       
              },
         error: function(response){
        //alert("error!");
         }
      });
  
      
 }, 500); // refresh every 500 milliseconds

chat_db.php
 


  $msg=null;
  $msg = strtolower($_GET['msg']);
  
  receive_msg($msg);


  function receive_msg($msg)
  {
    
 header("Content-type: application/json");
        //require_once("db.config.php");
       require_once '../../db.config.php';

     $dbh=null;
          $dbh = new PDO("mysql:host=" . wp_db('hostname') . ";dbname=" . wp_db('dbname'), wp_db('username'), wp_db('password'),   array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8") ); //POD處理中文的顯示的問題

 
         $sql_table = "SELECT * FROM yourTable ORDER BY id DESC LIMIT 1"; //監聽抓最新一筆

         foreach ($dbh->query($sql_table) as $row_table) {

          $message =   $row_table['message'];
       
          }      


          echo json_encode(
            array(                         
                    "message" =>$message                    
            )
          );
    
   }  


2013年8月19日 星期一

phpmyadmin

資料庫重命名 點選操作標籤 / 編輯

2013年6月13日 星期四

MySQL

$link = mysql_connect('localhost','root','tkbjacob'); 
if (!$link) { 
 die('Could not connect to MySQL: ' . mysql_error()); 
} 
echo 'Connection OK'; mysql_close($link); 

pdo測試
$hostname = 'localhost'; 
$username = 'root'; 
$password = 'password';
$db_name="name_db";


try{
    $db=new PDO("mysql:host=".$hostname.";
                dbname=".$db_name, $username, $password,
                array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
                //PDO::MYSQL_ATTR_INIT_COMMAND 設定編碼
                
    //echo '連線成功';
    $db->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION); //錯誤訊息提醒
    
    //Query SQL
    $sql="Select * from poi ";
    $result=$db->query($sql);    
    while($row=$result->fetch(PDO::FETCH_OBJ)){    
        //PDO::FETCH_OBJ 指定取出資料的型態
        echo $row->id."
";  
       
    }
    

    
    $db=null; //結束與資料庫連線
} 
catch(PDOException $e){
    //error message
    echo $e->getMessage(); 
}

優化你的 MySQL 數據庫運作

正確數據類型

2013年5月30日 星期四

mysql date

mysql常用日期query



//注意結尾,否則只會出現到前一天的資料 NOW()- INTERVAL 1

$sql = 'SELECT * FROM mission WHERE(NOW()- INTERVAL 1 DAY BETWEEN start AND end ) and state=1 order by start DESC ';

2013年5月28日 星期二

php onclick call a javascript function

html in php call a javascript function


 
$output_list  .= '<input type="checkbox"   checked="yes" onclick="mGroup('."'$row[$dbtable_icon]'".')">';




[CSS] 拋棄原生checkbox用CSS3自己簡單動手做

2013年5月16日 星期四

php mysql query explode

    



			  $mysqlQueryResult_explode = explode(",", $mysqlQueryResult);

			    for ($i=0;$i

2011年10月31日 星期一

[WordPress] wpdb資料庫


英文版的文章在這裡
wordpress提供了一個全局變量$wpdb來訪問wordpress數據庫,通過wpdb可以實現對數據庫的各種操作。這裡各種操作包括添加一個新表,查詢,刪除,更新​​等等。提供了處理用戶自定義數據的接口。注意在調用的函數里面要全局化這個變量。通過這個變量可以訪問數據庫中的任何表,但是僅限於一個數據庫,如果要訪問多個數據庫,需要重新實例化一個wpdb類。這裡只討論單個數據庫的情況。

查詢

<?php $wpdb->query(" DELETE FROM $wpdb->post WHERE post_id = '13′ “); ?>
其中query的參數是任何mysql語句。返回值是有多少行被選出、影響。如果出錯返回FALSE。

選出一個變量

<?php $wpdb->get_var('query',column_offset,row_offset); ?>
其中query為要查詢的mysql語句,如果為空的話,則表示從cache中選出。column_Offset和row_offet表示制定query返回值的第幾列和第幾行,缺省值為零。典型用法為:<?php $user_count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $wpdb->users;"));?> 這個sql只選出一個值,缺省的0行0列,即表示選出用戶數目。目前還不清楚,這里為什麼總是要加prepare在前面。

選出一行

<?php $wpdb->get_row('query', output_type, row_offset); ?>
query為要執行的mysql語句,output_type表示返回值是object,hash或者是數組;row_offset表示第幾行。

缺省情況下output_type為object。

$mylink = $wpdb->get_row("SELECT * FROM $wpdb->links WHERE link_id = 10");
echo $mylink->link_id; // prints "10"

如果output_type=ARRAY_A,那麼:

$mylink = $wpdb->get_row("SELECT * FROM $wpdb->links WHERE link_id = 10", ARRAY_A);
echo $mylink['link_id']; // prints "10"

如果output_type=ARRAY_N,那麼:

$mylink = $wpdb->get_row("SELECT * FROM $wpdb->links WHERE link_id = 10", ARRAY_N); 
echo $mylink[1]; // prints "10"

選出一列

<?php $wpdb->get_col('query',column_offset); ?>

一般選出

 $wpdb->get_results('query', output_type); 
例子:$fivesdrafts = $wpdb->get_results("SELECT ID, post_title FROM $wpdb->posts WHERE post_status = 'draft' AND post_author = 5");


foreach ($fivesdrafts as $fivesdraft) {
echo $fivesdraft->post_title;
}

插入一行

<?php $wpdb->insert( $table, $data, $format ); ?>
實例:$wpdb->insert( 'table', array( 'column1′ => 'value1′, 'column2′ => 123 ), array( '%s', '%d' ) )

更新

$wpdb->update( $table, $data, $where, $format = null, $where_format = null );
實例:$wpdb->update( 'table', array( 'column1' => 'value1', ' column2' => 'value2' ), array( 'ID' => 1 ), array( '%s', '%d' ), array( '%d' ) )

關於wpdb prepare

前面提到不清楚為什麼每個mysql語句都會包在prepare中,這裡給出解釋:因為mysql語句中可能含有單引號雙引號這樣的字符,如果不加處理直接送給mysql,可能會導致錯誤。於是這里通過一個prepare來對mysql語句進行預處理。prepare的語法是:
 $sql = $wpdb->prepare( 'query' [, value_parameter, value_parameter ... ] ); 
在query中可以包含%d,%S,%f,分別表示後面參數的類型是整數,字符和浮點,如果要顯示%號,則用%%,語法和C語言裡面的printf基本一樣。
到這里基本上就講完了。對一般數據庫的處理應該都沒有問題了。如果碰到問題可以在本文開始時提到的那篇文章中去查閱。
本文地址: http://www.bagualu.net/wordpress/?p=641轉載請註明

2011年7月31日 星期日

2011年7月21日 星期四

[PHP] Html form Update mysql

HTML表單值導入MySQL


先透過select,再抓key值,導到下一個介面,進行update


參考:Updating data in mysql



補充 解決 PHP/mySQL 資料庫讀取中文顯示亂碼或問號






php big5跟utf-8互轉的指令

big5 轉 utf-8
PHP 程式碼:
$str=iconv("big5","UTF-8",$str);

utf-8 轉 big5
PHP 程式碼:
$str=iconv("UTF-8","big5",$str);

2011年4月29日 星期五

max_join_size

Interesting as the sizes listed in the original problem are an indication that you had a 64 bit and have now installed the 32 bit packages. The limits that are reduced

Quote:
Warning: option 'max_join_size': unsigned value 18446744073709551615 adjusted to 4294967295
Warning: option 'select_limit': unsigned value 18446744073709551615 adjusted to 4294967295
The limit 18446744073709551615 is only available in 64 Bit MySQL, the default for 32 bit is the value to which it has reduced ie. 4294967295.

The other problem you have listed above may also be an issue however it seems you may have switched from 64 to 32 bit packages for the MySQL server.

2011年4月27日 星期三

#1045 - Access denied for user 'root'@'localhost' (using password: NO)

另一種情況:


Cannot start session without errors, please check errors given in your PHP and/or webserver log file and configure your PHP installation properly.


解決方法:

/var/www/html/phpmyadmin/  config.sample.inc.php  →  config.inc.php
 wamp directory \apps\phpmyadmin\ config.inc.php

phpmyadmin出現 #1045 - Access denied for user 'root'@'localhost' (using password: NO)的錯誤,那麼應該看下面phpmyadmin的設置!

當然,對於phpMyAdmin文件夾內的config.inc.php文件進行MySQL帳號和密碼的修改,

文件config.inc.php是phpMyAdmin的配置文件

對於config.inc.php文件,最重要的即是修改加入phpMyAdmin連接MySQL的用戶名和密碼。尋找到代碼行:



// $cfg['Servers'][$i]['controluser'] = 'pma';
// $cfg['Servers'][$i]['controlpass'] = 'pmapass';



將「//」註釋號刪除,將phpmysqlMySQL中配置的用戶名和密碼刪除(遠程服務器的請聯繫你的空間服務商),比如這裡:



$cfg['Servers'][$i]['controluser'] = '';
$cfg['Servers'][$i]['controlpass'] = '';





Error

The configuration file now needs a secret passphrase (blowfish_secret).






/* Authentication type */
$cfg['Servers'][$i]['auth_type'] = 'cookie';

$cfg['Servers'][$i]['auth_type'] = 'http';

mysql: unrecognized service

service mysql start出錯,mysql啟動不了,解決mysql: unrecognized service錯誤的方法如下:
[root@ctohome.com ~]# service mysql start
mysql: unrecognized service
[root@ctohome.com ~]# service mysql restart
mysql: unrecognized service

[root@ctohome.com ~]# rpm -q mysql   查詢發現mysql已經正常安裝
mysql-5.1.52-jason.1

[root@ctohome.com ~]# /etc/rc.d/init.d/mysqld start  直接啟動沒問題
Starting mysqld:  [  OK  ]


[root@ctohome.com ~]# ls  /etc/rc.d/init.d/mysqld  -l
-rwxr-xr-x 1 root root 5509 Dec 18 02:31 /etc/rc.d/init.d/mysqld

[root@ctohome.com ~]# chkconfig mysqld on 設置mysql開機啟動

[root@ctohome.com ~]# chmod 755 /etc/rc.d/init.d/mysqld  修改mysqld執行權限

[root@ctohome.com ~]# service mysqld start  搞定
Starting mysqld:  [  OK  ]
[root@ctohome.com ~]# service mysqld start
Starting mysqld:  [  OK  ]
[root@ctohome.com ~]# service mysqld status
mysqld (pid 9487) is running...

引自: http://www.ctohome.com/FuWuQi/aa/511.html