<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://www.jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>http://www.jackxiang.com/post//</link>
<title><![CDATA[php gtk+连接mysql的代码]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[WEB2.0]]></category>
<pubDate>Sun, 29 Jun 2008 09:17:43 +0000</pubDate> 
<guid>http://www.jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	<br/><div class="code">&lt;?<br/>/*<br/>A little sample script that takes SQL query from user, sends it to the MySQL server and<br/>displays the result of query in new window.<br/>DON&#039;T FORGET TO CHANGE SERVER, USERNAME AND PASSWORD IN MYSQL_PCONNECT FUNCTION!!<br/>I&#039;ll be glad for any comments.<br/>Adam Rambousek - rambousek@volny.cz<br/>*/<br/><br/>if (strtoupper(substr(PHP_OS, 0, 3)) == &#039;WIN&#039;)<br/>dl(&#039;php_gtk.dll&#039;);<br/>else<br/>dl(&#039;php_gtk.so&#039;);<br/><br/>$windows = array();<br/><br/>function delete_event($window, $event)<br/>&#123;<br/>$window-&gt;hide();<br/>return true;<br/>&#125;<br/><br/>function close_window($widget)<br/>&#123;<br/>$window = $widget-&gt;get_toplevel();<br/>$window-&gt;hide();<br/>&#125;<br/><br/>/*<br/>Called when clist column is clicked. It sets sorting by the clicked column.<br/>*/<br/>function clist_click_column($clist, $column) &#123;<br/>$clist-&gt;set_sort_column($column);<br/>$clist-&gt;sort();<br/>&#125;<br/><br/><br/>/*<br/>Function displaying the result of query.<br/>*/<br/>function do_query($query)<br/>&#123;<br/>global $windows;<br/><br/>//if the query_window is opened, let&#039;s close it<br/>if (isset($windows&#91;&#039;query_window&#039;&#93;)) &#123;<br/>close_window($windows&#91;&#039;query_window&#039;&#93;);<br/>&#125;<br/><br/>$window = &amp;new GtkWindow;<br/>$windows&#91;&#039;query_window&#039;&#93; = $window;<br/>$window-&gt;set_name(&#039;query_window&#039;);<br/>$window-&gt;connect(&#039;delete-event&#039;, &#039;delete_event&#039;);<br/>$window-&gt;set_policy(false, true,false);<br/>$window-&gt;set_title(&#039;Query result&#039;);<br/>$window-&gt;set_uposition(220,85);<br/><br/>$box1 = &amp;new GtkVBox();<br/>$window-&gt;add($box1);<br/><br/>//frame displaying entered sql query<br/>$frame = &amp;new GtkFrame(&#039;MySQL Query&#039;);<br/>$box1-&gt;pack_start($frame,false);<br/>$label = &amp;new GtkLabel($query-&gt;get_text());<br/>$frame-&gt;add($label);<br/><br/>//frame displaying clist with the query result<br/>$frame = &amp;new GtkFrame(&#039;MySQL Query Result&#039;);<br/>$box1-&gt;pack_start($frame,true);<br/><br/>//we&#039;ll display the result with scrollbars<br/>$scrolled_win = &amp;new GtkScrolledWindow();<br/>$scrolled_win-&gt;set_border_width(5);<br/>$scrolled_win-&gt;set_policy(GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);<br/>$frame-&gt;add($scrolled_win);<br/><br/>/*here we deal with the result<br/>if mysql_query called with the query entered in main window, return a result<br/>we can display clist<br/>*/&nbsp;&nbsp;<br/>if ($result = mysql_query($query-&gt;get_text())) &#123;<br/>/*<br/>at first, keys array contains the names of columns<br/>*/<br/>if ($data = mysql_fetch_array($result)) &#123;<br/>$i=0;<br/>$keys = array();<br/>while (list($key,$val) = each($data)) &#123;<br/>if ($i%2) $keys&#91;&#93;=$key;<br/>$i++;<br/>&#125;<br/>&#125;<br/><br/>/*<br/>now we can prepare the clist, keys are the titles of columns and the number<br/>of columns is equal to the number of keys<br/>*/&nbsp;&nbsp;<br/>$clist = &amp;new GtkCList(count($keys), $keys);<br/>$clist-&gt;connect(&#039;click_column&#039;, &#039;clist_click_column&#039;);<br/><br/>//we sets the auto_resize for each column<br/>for ($i=0;$i&lt;count($keys);$i++) $clist-&gt;set_column_auto_resize($i, true);<br/>$scrolled_win-&gt;add($clist);<br/><br/>/*<br/>now the data from result<br/>we get the data from each row to row_data array and then we append this<br/>array to the clist as a new row<br/>*/<br/>do &#123;<br/>for($i=0; $i &lt; count($data)/2; $i++)&#123;<br/>$row_data&#91;$i&#93; = $data&#91;$i&#93;;<br/>&#125;<br/>$clist-&gt;append($row_data);<br/>&#125; while ($data = mysql_fetch_array($result));<br/>&#125;<br/><br/><br/>$button = &amp;new GtkButton(&#039;close window&#039;);<br/>$button-&gt;connect(&#039;clicked&#039;, &#039;close_window&#039;);<br/>$box1-&gt;pack_start($button,false);<br/>$button-&gt;set_flags(GTK_CAN_DEFAULT);<br/>$button-&gt;grab_default();<br/><br/>$window-&gt;show_all();<br/>&#125;<br/><br/>function main_window()<br/>&#123;<br/>$window = &amp;new GtkWindow();<br/>$window-&gt;set_policy(false,true,false);<br/>$window-&gt;set_name(&#039;main_window&#039;);<br/>$window-&gt;set_title(&#039;MySQL Query sample&#039;);<br/>$window-&gt;set_uposition(80,80);<br/><br/>$window-&gt;connect_object(&#039;destroy&#039;, array(&#039;gtk&#039;, &#039;main_quit&#039;));<br/>$window-&gt;connect_object(&#039;delete-event&#039;, array(&#039;gtk&#039;, &#039;false&#039;));<br/><br/>$box1 = &amp;new GtkVBox();<br/>$window-&gt;add($box1);<br/><br/>$frame = &amp;new GtkFrame(&#039;MySQL Query&#039;);<br/>$box1-&gt;pack_start($frame,false);<br/><br/>$entry = &amp;new GtkEntry();<br/>$frame-&gt;add($entry);<br/><br/>$separator = &amp;new GtkHSeparator();<br/>$box1-&gt;pack_start($separator,false);<br/><br/>$button = &amp;new GtkButton(&#039;Do Query&#039;);<br/>$button-&gt;connect_object(&#039;clicked&#039;, &#039;do_query&#039;,$entry);<br/>$box1-&gt;add($button);<br/><br/>$separator = &amp;new GtkHSeparator();<br/>$box1-&gt;pack_start($separator,false);<br/><br/>$button = &amp;new GtkButton(&#039;Quit&#039;);<br/>$button-&gt;connect_object(&#039;clicked&#039;, array(&#039;gtk&#039;, &#039;main_quit&#039;));<br/>$box1-&gt;add($button);<br/><br/><br/>$window-&gt;show_all();<br/>&#125;<br/><br/>mysql_pconnect(&quot;SERVER&quot;,&quot;USERNAME&quot;,&quot;PASSWORD&quot;) or die(&quot;can&#039;t connect to server&quot;);<br/>main_window();<br/>Gtk::main();<br/><br/>?&gt; </div><br/><br/><br/><br/><br/><div class="code">&lt;?<br/><br/>if (!class_exists(&#039;gtk&#039;)) &#123;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;if (strtoupper(substr(PHP_OS, 0, 3)) == &#039;WIN&#039;)<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dl(&#039;php_gtk.dll&#039;);<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;else<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dl(&#039;php_gtk.so&#039;);<br/><br/>&#125;<br/><br/> <br/><br/>function destroy() &#123;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;Gtk::main_quit();<br/><br/>&#125;<br/><br/> <br/><br/>$window = &amp;new GtkWindow();<br/><br/>$window-&gt;set_title(&quot;MySQL Manager&quot;);<br/><br/>$window-&gt;set_usize(300,300);<br/><br/>$window-&gt;connect(&#039;destroy&#039;, &#039;destroy&#039;);<br/><br/>$window-&gt;set_border_width(10);<br/><br/>$table=&amp;new gtktable(5,3);<br/><br/>$window-&gt;add($table);<br/><br/> <br/><br/>//add text boxes, button, and label<br/><br/>$usertext=&amp;new gtklabel();<br/><br/>$usertext-&gt;set_text(&quot;Username:&quot;);<br/><br/>$table-&gt;attach($usertext,1,2,1,2);<br/><br/>$user=&amp;new gtkentry();<br/><br/>$table-&gt;attach($user,2,3,1,2);<br/><br/>$passtext=&amp;new gtklabel();<br/><br/>$passtext-&gt;set_text(&quot;Password:&quot;);<br/><br/>$table-&gt;attach($passtext,1,2,2,3);<br/><br/>$pass=&amp;new gtkentry();<br/><br/>$table-&gt;attach($pass,2,3,2,3);<br/><br/>$sertext=&amp;new gtklabel();<br/><br/>$sertext-&gt;set_text(&quot;Server:&quot;);<br/><br/>$table-&gt;attach($sertext,1,2,3,4);<br/><br/>$server=&amp;new gtkentry();<br/><br/>$table-&gt;attach($server,2,3,3,4);<br/><br/>$conb=&amp;new gtkbutton(&quot;Connect!&quot;);<br/><br/>$conb-&gt;connect(&#039;clicked&#039;,&#039;mconnect&#039;);<br/><br/>$table-&gt;attach($conb,1,3,4,5);<br/><br/> <br/><br/>function put($what,$where) &#123;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;$where-&gt;set_text($what);<br/><br/>&#125;&nbsp;&nbsp; <br/><br/> <br/><br/>function mconnect() &#123;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;global $window,$pass,$user,$server;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;$pass=$pass-&gt;get_text();<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;$user=$user-&gt;get_text();<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;$server=$server-&gt;get_text();<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;$conn=mysql_connect($server,$user,$pass);<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;mysql_select_db(&quot;simtown&quot;);<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;$q=&quot;select * from users&quot;;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;while ($row=mysql_query($q)) &#123;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print $row&#91;0&#93;;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;mysql_close($conn);<br/><br/>&#125;<br/><br/> <br/><br/>$window-&gt;show_all();<br/><br/> <br/><br/>Gtk::main();<br/><br/>?&gt; </div>
]]>
</description>
</item><item>
<link>http://www.jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] php gtk+连接mysql的代码]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://www.jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>