zoukankan      html  css  js  c++  java
  • JQuery学习(4-2-phpserver端1)


        主要内容:介绍图片的上传过程,涉及PHP跟JQuery;

        1. 读取配置文件,连接MySQL数据库。

           配置文件主要实username和password。

    3-5.php

    <?php
    /*
    * version : 20141108
    */
    
    /*
    * 定义一个常量
    */
    define("EQUAL","=");
    define("SPACE","");
    
    function get_content($file){
    	if(!file_exists($file)) return false; 
    	return file_get_contents($file);
    }
    
    function get_config($str, $ini, $type="string"){ 
    
    		if ($type=="int"){ 
    			$config = preg_match("/".preg_quote($ini)."=(.*);/", $str, $res); 
    			if($config==0) return false;
    		} 
    		else{ 
    			$config = preg_match("/".preg_quote($ini)."="(.*)";/", $str, $res); 
    			if($config==0) return false;
    		} 
    		$result=explode(EQUAL,$res[0]);
    		return preg_replace("/("|'|;)/",SPACE,$result[1]);
    		
    } 
    
    ?

    >

        2. 连接MySQL数据库;

        这里使用PHP提供的odbc类。

        首先安装数据源驱动,类如mysql-connector-odbc-5.3.4-win32。然后在ODBC数据源管理当中配置就OK了。



        2.1 写数据库的连接操作

    <?php
    	/*
    	* version : 20141109
    	* made dy : neojos
    	*/
    	include_once("3-5.php");
    	
    	class dbSource{
    		
    		function __construct(){
    			
    			$dbString=get_content("config.ini");
    			$server=get_config($dbString,"server");
    			echo $dbname=get_config($dbString,"userName");
    			echo $dbpwd=get_config($dbString,"password");
    			odbc_connect("DRIVER={MySQL ODBC 5.3 ANSI Driver};",$dbname,$dbpwd) or handle_error("",odbc_error()); 
    
    		}
    		
    		function handle_error($user_error_message,$system_error_message){
    			header("Location:3-6.php?"."error_message={$user_error_message}&".
    				"system_error={$system_error_message}");
    			exit();
    		}
    	}
    	
    	$db=new dbSource();
    	
    ?

    >

  • 相关阅读:
    python自动化测试(2)--读取excel中的测试用例并使用列表进行存放
    Numpy学习记录
    Tensorflow环境安装记录--无法识别GPU的问题
    Tensorflow框架学习(1)--CNN的实现
    IDEA创建springboot项目总是创建失败问题的解决
    java_集合知识点小结
    java易错知识点汇总_1
    struts2 中文件的位置问题
    struts2 action中的私有变量
    span 标记 width 设置
  • 原文地址:https://www.cnblogs.com/zsychanpin/p/6756687.html
Copyright © 2011-2022 走看看